Commit 934e5995 by 杨树贤

Initial commit

parents
Showing with 4865 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
/node_modules
/public/hot
/public/storage
/storage/*.key
/storage/framework
/storage/logs
/.idea
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class AnalysisLog extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'An:Log {param1=all}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$FileName=$this->argument('param1');
$f = fopen(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$FileName, 'r');
$x = fopen(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'An'.$FileName.'.csv','w');
$i=0;
$ii=0;
$DB=DB::connection('spu')->table('lie_an_log');
$Arr=[];
while (!feof($f)) {
$i++;
$res = fgetcsv($f);
if(!empty($res[0])){
$ii++;
if($ii==1){
$data=['time'=>$this->get_between($res[0],'[',']')];
$data['action']=true;
fputcsv($x,$data);
}
if($ii==2){//不是基石系統的日誌
if(strpos($res[0],'footstone.ichunt.net') === false) continue;
}
if($ii>2){
$res[0]=substr($res[0],21);
$data['action']=substr($res[0],0,strpos($res[0],'()'));//截取方法
if(!empty($Arr[$data['action']]))continue;
$Arr[$data['action']]=true;
$data['file']=substr($res[0],strpos($res[0],'()')+3);
if(strpos($data['file'],'footstone.ichunt.net') === false) continue;
$data['action']=$data['action'].'()';
fputcsv($x,$data);
}
}else{
$ii=0;
}
}
dump($i);
}
function get_between($input, $start, $end) {
$substr = substr($input, strlen($start)+strpos($input, $start),(strlen($input) - strpos($input, $end))*(-1));
return $substr;
}
}
<?php
namespace App\Console\Commands;
use App\Model\GoodsModel;
use Illuminate\Console\Command;
class DcSelfGoods extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'DcSelfGoods';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$GoodsModel=new GoodsModel();
$count=10;
$map=[
['goods.status','=',1],
['stock','>',0]
];
$filename=date('Y-m-d-H-i-s') . '-' . uniqid() . '.csv';
$x=fopen(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$filename,'w');
$Arr=['SKUID','商品名字','制造商','标准包装量'];
for($i=1;$i<10;$i++){
$Arr[]='阶梯'.$i;
$Arr[]='价格'.$i;
}
foreach ($Arr as $k=>$v){
$Arr[$k]=iconv('utf-8','gbk//IGNORE',$v);
}
fputcsv($x,$Arr);
for ($p = 1; $p < $count + 1; $p++) {
$list = $GoodsModel->where($map)->join('brand','goods.brand_id','=','brand.brand_id')->select('goods_id',
'goods_name','goods.goods_id','ladder_price','brand_name','mpq')->paginate(1000, ['*'], '', $p)->toArray();
$count = $list['last_page'];
foreach ($list['data'] as $k=>$v){
$Arr=[];
$Arr[0]=$v['goods_id'];
$Arr[1]=$v['goods_name'];
$Arr[2]=$v['brand_name'];
$Arr[3]=$v['mpq'];
$price=json_decode($v['ladder_price'],true);
if(is_array($price)){
foreach ($price as $k1=>$v1){
array_push($Arr,$v1['purchases']);
array_push($Arr,$v1['price_cn']);
}
}
foreach ($Arr as $k2=>$v2){
$Arr[$k2]=iconv('utf-8','gbk//IGNORE',$v2);
}
fputcsv($x,$Arr);
}
}
}
}
<?php
namespace App\Console\Commands;
use App\Jobs\GoodsLog;
use App\Model\GoodsModel;
use Illuminate\Console\Command;
use Storage;
class DeleteSelfGoods extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'del:selfgoods';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$info=Storage::disk('uploads')->get('DeleteSelfGoods.txt');
if(!$info){
echo 'fail';
return false;
}
$Arr=explode(',',$info);
$i=0;
$Goods=new GoodsModel();
foreach ($Arr as $k=>$v){
$Find=$Goods->where('goods_id','=',$v)
->select('status','stock','wait_stock','cost','new_cost')->first();
if(!$Find){
echo $v.'->没有查找到商品'."\r\n";
continue;
}
$Find=$Find->toArray();
if($Find['stock']>0 || $Find['wait_stock']>0 || $Find['cost']>0 || $Find['new_cost']>0){
echo $v.'->当前商品有库存或有入库,无法删除'."\r\n";
continue;
}
$result=$Goods->where('goods_id','=',$v)->update(['status'=>4,'update_time'=>time(),'sale_time'=>time()]);
if(!$result){
echo $v.'->删除失败'."\r\n";
continue;
}
//更新redis,推送到wms
$Goods->UpdateGoodsRedis($v,'',true);//不计状态
//商品日志记录
$collert['add_user']=0;
$collert['type']=12;
$collert['update_time']=time();
$collert['goods_id']=$v;
dispatch(new GoodsLog($collert));
echo $v.'->删除成功'."\r\n";
$i++;
}
echo '->complete,总计'.count($Arr).',成功:'.$i.'个';
}
}
<?php
namespace App\Console\Commands;
use App\Model\ResourceModel;
use Illuminate\Console\Command;
use RedisDB;
class InitializationResource extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'InSelfGoodsRe';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$Model=new ResourceModel();
$fieldArr = ['id','url'];
$count = 100;
$i = 0;
$Redis = RedisDB::connection();
$pre = Config('perm.SELF_REDIS_PRE');
for ($p = 1; $p < $count + 1; $p++) {
$list = $Model->select($fieldArr)->where('status','=', '1')->paginate(1000,['*'],'',$p)->toArray();
foreach ($list['data'] as $key => $value) {
$i++;
echo $i.'->';
$resourceDetails['url'] = $value['url'];
$re = $Redis->hset($pre.'SelfGoodsSource', $value['id'] ,json_encode($resourceDetails));
}
$count = $list['last_page'];
}
echo 'complete';
}
}
<?php
namespace App\Console\Commands;
use App\Model\SelfBrandModel;
use Illuminate\Console\Command;
use RedisDB;
class InitializationSelfBrand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ISelfBrand';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$BrandModel=new SelfBrandModel();
$list=$BrandModel->select('brand_logo','brand_id','brand_name','brand_area','status')->get()->toArray();
$pre=Config('perm.SELF_REDIS_PRE');
$Redis=RedisDB::connection();
foreach ($list as $k=>$v){
echo $v['brand_id'].'->';
$Redis->hset($pre.'Brand',$v['brand_id'],json_encode($v));
}
echo 'complete';
}
}
<?php
namespace App\Console\Commands;
use App\Model\SelfClassifyModel;
use Illuminate\Console\Command;
use RedisDB;
class InitializationSelfClass extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ISelfClass';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$Redis=RedisDB::connection();
$SelfModel=new SelfClassifyModel();
$list=$SelfModel->select('class_id')->get()->toArray();
foreach ($list as $k=>$v){
echo $v['class_id'].'->';
$SelfModel->ProduceClassRedis($v['class_id'],false,$Redis);
}
echo 'complete';
}
}
<?php
namespace App\Console\Commands;
use App\Model\GoodsModel;
use App\Model\RedisModel;
use Illuminate\Console\Command;
use RedisDB;
class InitializationSelfGoods extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'InSelfGoods';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$GoodsModel=new GoodsModel();
$count=100;
$Redis=new RedisModel();
for ($p = 1; $p < $count + 1; $p++) {
$list = $GoodsModel->select('goods_id')->paginate(1000, ['*'], '', $p)->toArray();
$count=$list['last_page'];
foreach ($list['data'] as $k=>$v){
echo $v['goods_id'].'->';
$GoodsModel->UpdateGoodsRedis($v['goods_id'],$Redis, true);
}
}
echo 'complete';
}
}
<?php
namespace App\Console\Commands;
use App\Model\GoodsModel;
use App\Model\SelfBrandModel;
use Illuminate\Console\Command;
use DB;
class InitializationSelfStaticCost extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'InSelfStaCost';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$time = strtotime('2020-03-28');
$GoodsModel = new GoodsModel();
$result = $GoodsModel->where('cost','>',0)->update(['static_cost'=> \DB::raw('cost'),'static_cost_expire_time'=>$time]);
dump($result);
}
}
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
Commands\InitializationSelfGoods::class,//初始化自营商品到redis
Commands\InitializationResource::class,//初始化自营商品到redis
Commands\DcSelfGoods::class,//导出自营商品
Commands\AnalysisLog::class,//解析日誌
Commands\DeleteSelfGoods::class,//删除指定自营商品(软删除)
Commands\InitializationSelfStaticCost::class,//初始化自营静态成本
Commands\InitializationSelfBrand::class,//初始化自营品牌
Commands\InitializationSelfClass::class,//初始化自营分类
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
class BatchController extends Controller
{
public function Entrance(Request $request, $id)
{
//统一入口
$this->$id($request, $id);
}
private function Export($errcode=0, $errmsg='成功', $data='')
{
echo json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data]);
exit();
}
//生成spu唯一识别信息
private function create_spu_mongo()
{
set_time_limit(0);
$starttime = explode(' ', microtime());
echo microtime();
$mongo=new \MongoClient(env('MONGO_HOST', ''));
$mongodb=$mongo->ichunt->spu;
$count=100;
$db=DB::connection('spu');
for ($table=0;$table<10;$table++) {
for ($p=1;$p<$count+1;$p++) {
$data=[];
$list=$db->table('lie_spu_'.$table)->select('spu_name', 'brand_id', 'spu_id')->paginate(1000, ['*'], '', $p);
foreach ($list as $k=>$v) {
$data[]=[
'spu_id'=>$v->spu_id,
'spu_name'=>$v->spu_name,
'brand_id'=>$v->brand_id
];
}
$result=$mongodb->batchInsert($data);
$count=$list->lastPage();
}
}
//程序运行时间
$endtime = explode(' ', microtime());
$thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime = round($thistime, 3);
echo "本程序执行耗时:".$thistime." 秒。".time();
}
private function create_sku_mongo()
{
set_time_limit(0);
$starttime = explode(' ', microtime());
echo microtime();
$mongo=new \MongoClient(env('MONGO_HOST', ''));
$mongodb=$mongo->ichunt->sku;
$count=100;
for ($dbcode=0;$dbcode<10;$dbcode++) {
$db=DB::connection('sku_'.$dbcode);
for ($table=0;$table<10;$table++) {
for ($p=1;$p<$count+1;$p++) {
$data=[];
$list=$db->table('lie_sku_'.$table)->select('goods_id', 'spu_id', 'moq', 'supplier_id')->paginate(10000, ['*'], '', $p);
foreach ($list as $k=>$v) {
$data[]=[
'goods_id'=>intval($v->goods_id),
'spu_id' =>intval($v->spu_id),
'supplier_id'=>intval($v->supplier_id),
'moq'=>intval($v->moq)
];
}
$mongodb->batchInsert($data);
$count=$list->lastPage();
}
}
}
//程序运行时间
$endtime = explode(' ', microtime());
$thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime = round($thistime, 3);
echo "本程序执行耗时:".$thistime." 秒。".time();
}
private function create_spu_redis($request)
{
set_time_limit(0);
$redis=RedisDB::connection();
$db=DB::connection('spu');
$table=$request->input('table');
$data=[];
$list=$db->table('lie_spu_'.$table)
->select('spu_id', 'class_id1', 'class_id2', 'brand_id', 'class_id3', 'spu_name', 'status', 'images_l', 'images_s', 'encap', 'pdf', 'spu_brief', 'has_rohs', 'attrs', 'spu_detail', 'sale_time', 'create_time', 'update_time', 'remark', 'bussiness_area')
->paginate(1000);
foreach ($list as $k=>$v) {
$info=(array)$v;
$info['class_id']=0;
if (!empty($info['class_id1'])) {
$info['class_id']=$info['class_id1'];
}
if (!empty($info['class_id2'])) {
$info['class_id']=$info['class_id2'];
}
if (!empty($info['class_id3'])) {
$info['class_id']=$info['class_id3'];
}
$info['class_name']=$redis->hget('class', $info['class_id']);
$info['brand_name']=$redis->hget('brand', $info['brand_id']);
switch ($info['status']) {
case 0:
$info['status_name']='审核中';
break;
case 1:
$info['status_name']='上架';
break;
case 2:
$info['status_name']='审核不通过';
break;
case 3:
$info['status_name']='下架';
break;
default:
$info['status_name']='未知';
}
$info['create_time_s']=date('Y-m-d H:i', $info['create_time']);
$data[$v->spu_id]=json_encode($info);
}
$result=$redis->hmset('spu', $data);
$objdata['count']=$list->count();
$objdata['last_page']=$list->lastPage();
if ($result=='OK') {
$this->Export(0, '', $objdata);
} else {
$this->Export(20001, '写入Redis出错');
}
}
//生成spu唯一识别信息
private function spu_redis()
{
echo 'kkk';
die;
set_time_limit(0);
$starttime = explode(' ', microtime());
echo microtime();
$redis=RedisDB::connection();
$count=100;
$db=DB::connection('spu');
for ($table=0;$table<10;$table++) {
for ($p=1;$p<$count+1;$p++) {
$data=[];
$list=$db->table('lie_spu_'.$table)
->select('spu_id', 'class_id1', 'class_id2', 'brand_id', 'class_id3', 'spu_name', 'status', 'images_l', 'images_s', 'encap', 'pdf', 'spu_brief', 'has_rohs', 'attrs', 'spu_detail', 'sale_time', 'create_time', 'update_time', 'remark', 'bussiness_area')
->paginate(1000, ['*'], '', $p);
foreach ($list as $k=>$v) {
$v=(array)$v;
$data[$v['spu_id']]=json_encode($v);
}
$result=$redis->hmset('spu', $data);
$count=$list->lastPage();
}
}
//程序运行时间
$endtime = explode(' ', microtime());
$thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime = round($thistime, 3);
echo "本程序执行耗时:".$thistime." 秒。".time();
}
private function sku_redis()
{
}
}
<?php
namespace App\Http\Controllers;
use App\Model\SelfBrandModel;
use Illuminate\Http\Request;
class BrandApiController extends Controller
{
public function Entrance(Request $request, $id)
{
return $this->$id($request, $id);
}
//品牌列表
private function SelfBrandList($request)
{
$Arr=['brand_name','brand_id','status','brand_area'];
$collert = $request->only($Arr);
$limit = $request->input('limit',10);
$collert = TrimX($collert, true, $Arr);
$map=[];
foreach ($collert as $k=>$v) {
if ($k=='brand_name') {
$map[]=['brand_name','like',trim($v).'%'];
} else {
$map[]=[$k,'=',trim($v)];
}
}
$Model=new SelfBrandModel();
$data = $Model->ApiSelfBrandList($map, $limit);
return $this->apiReturn(0, 'ok', $data);
}
//新增/编辑品牌
private function ApiSaveSelfBrand($request)
{
$Model=new SelfBrandModel();
$collert=$request->only(['brand_id','brand_name','brand_logo','brand_brief','main_product','brand_desc','brand_area','status']);
$Arr=['brand_id','brand_name','brand_logo','brand_brief','main_product','brand_desc','brand_area','status'];
$collert=TrimX($collert, false, $Arr);
if (empty($collert)) {
return $this->apiReturn(10001,'缺少必须参数');
}
$Find=$Model->ApiGetBrandByName($collert['brand_name']);
if (!empty($collert['brand_id'])) {
if ($Find && $Find['brand_id'] != $collert['brand_id']) {
return $this->apiReturn(10002, '已经存在该品牌');
}
}
$result = $Model->ApiSaveSelfBrand($collert);
if(!$result){
return $this->apiReturn(10003, '保存失败');
}
return $this->apiReturn(0, '保存成功');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\SelfBrandModel;
use Illuminate\Http\Request;
class brandWebController extends Controller
{
public function Entrance(Request $request, $id='index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
private function SelfBrandList($request)
{
$status=Config('field.BrandStatus');
$BrandArea=config('field.BrandArea');
$this->data['status'] = $status;
$this->data['BrandArea'] = $BrandArea;
return $this->view('自营品牌列表');
}
private function SaveSelfBrand($request)
{
$Model=new SelfBrandModel();
$info=$Model->BrandInfo($request->input('brand_id'));
$BrandArea=config('field.BrandArea');
$this->data['BrandArea'] = $BrandArea;
$this->data['info'] = $info;
return $this->view('新增编辑自营品牌');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\ClassifyAttrModel;
use App\Model\ExamineModel;
use App\Model\GoodsModel;
use App\Model\HistoryPriceModel;
use App\Model\OfferModel;
use App\Model\RedisModel;
use App\Model\ResourceModel;
use App\Model\SampleClassModel;
use App\Model\SampleModel;
use App\Model\SelfClassifyModel;
use App\Model\SelfFinancialClassifyModel;
use App\Model\SupplierChannelModel;
use App\Model\UnitModel;
use App\Model\UploadLogModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Storage;
use Excel;
class ClassApiController extends Controller
{
public function Entrance(Request $request, $id)
{
return $this->$id($request, $id);
}
//修改分类阶梯参数
private function ApiSaveClassLadder()
{
$Model=new SelfClassifyModel();
$data=$Model->ApiSaveClassLadder();
$this->Export($data);
}
//自营批量上传列表
private function ApiUploadGoods()
{
$Model=new UploadLogModel();
$data=$Model->UploadLog();
$this->ExportLayui(0, '成功', $data['data'], $data['total']);
}
//分类开关
private function ApiSelfClassSwitch($request)
{
$arr=['status','class_id'];
$collert=$request->only($arr);
$collert=TrimX($collert, true, $arr);
if (empty($collert['class_id']) || empty($collert['status'])) {
return $this->apiReturn(10001,'缺少必须参数');
}
$ClassModel=new SelfClassifyModel();
$result=$ClassModel->ApiSelfClassSwitch($collert);
if (!$result) {
return $this->apiReturn(10002,'修改状态失败');
}
return $this->apiReturn(0,'修改成功');
}
//删除参数
private function ApiDeleteAttr($request)
{
$arr = ['class_id','attr_id'];
$collert = $request->only($arr);
if (empty($collert['attr_id']) || empty($collert['class_id'])) {
return $this->apiReturn(10001,'缺少必须参数');
}
$AttrModel=new ClassifyAttrModel();
$result = $AttrModel->ApiDeleteAttr($collert);
if(!$result){
return $this->apiReturn(10002, '删除失败');
}
return $this->apiReturn(0, '删除成功');
}
//编辑分类基本信息
private function ApiSaveSelfClassify($request)
{
$Arr=['class_id','parent_id','class_name','status','sort','class_icon','financial_classify_id'];
$collert=$request->only($Arr);
$collert=TrimX($collert, true, $Arr);
if ((empty($collert['parent_id']) && $collert['parent_id']!=0) || empty($collert['class_name']) || (!empty($collert['parent_id']!=0) && !empty($collert['class_id']) && empty($collert['financial_classify_id']))) {
return $this->apiReturn(10001,'缺少必须参数');
}
if (empty($collert['status'])) {
$collert['status']=3;
}
$Model = new SelfClassifyModel();
$data = $Model->ApiSaveSelfClassify($collert, $request->user->userId);
if(!$data){
return $this->apiReturn(10002, '保存失败');
}
return $this->apiReturn(0, '保存成功');
}
//编辑分类参数
private function ApiSaveClassAttr($request)
{
$collert = $request->only('class_id', 'attr_id', 'attr_name', 'value');
$collert=TrimX($collert, true, ['class_id','attr_id','attr_name','value']);
if (empty($collert)) {
return $this->apiReturn(10001,'缺少必须参数');
}
if (!empty($collert['value'])) {//去掉重复值,转换成json
foreach ($collert['value'] as $k=>$v) {
if (!empty($v)) {
$collert['value'][$k]=TrimX($v);
}
}
$collert['value']=json_encode(array_unique($collert['value']));
}
$Model=new ClassifyAttrModel();
$data=$Model->ApiSaveClassAttr($collert);
if(!$data){
return $this->apiReturn(10002, '保存失败');
}
return $this->apiReturn(0,'保存成功');
}
private function ApiSetupIsNameList($request)
{
$Model=new ClassifyAttrModel();
$list=$Model->ClassifyList();
$ClassModel=new SelfClassifyModel();
$custom=$ClassModel->HDCustom($request->input('class_id'));
$list=array_merge_recursive($list, $custom);
$list=arraySequence($list, 'name_sort');
return $this->apiReturn(0, '成功', ['data'=>$list]);
}
//设置分类sku_name生成规则
private function ApiSetUpIsName($request)
{
$Verification=ServiceTime($request->route('key'));
if ($Verification!==true) {
return $this->apiReturn(10006, '本服务'.$Verification.'s内仅能提交一次,请稍后');
}
$Arr=['attr_id','attr_name','is_name','name_sort'];
$collert = $request->only($Arr);
$ClassID = $request->only('class_id');
if (empty($ClassID['class_id'])) {
return $this->apiReturn(10003,'缺少分类ID');
}
$collert=TrimX($collert, true, $Arr);
foreach ($Arr as $k=>$v) {
if (empty($collert[$v]) || !is_array($collert[$v])) {
return $this->apiReturn(10001,'参数错误',$v);
}
}
$Model=new ClassifyAttrModel();
$result = $Model->ApiSetUpIsName($collert, $ClassID, $request->user->userId);
if(!$result){
return $this->apiReturn(10002, '保存失败');
}
return $this->apiReturn(0, '保存成功');
}
//获取分类
private function ObtainTaxClass($request)
{
$classify_sn = $request->input('classify_sn') ? $request->input('classify_sn'):0;
$level = $request->input('level') ? $request->input('level') : 0;
$level = $level + 3;
$Model = new SelfFinancialClassifyModel();
$list= $Model
->where('status', 1)
->where('classify_parent_sn', $classify_sn)
->where('level', $level)
->get();
return $this->apiReturn(0, '', ['data'=>$list]);
}
//删除分类缓存
private function ApiDeleteSelfClassCache()
{
$Redis=new RedisModel();
$result = $Redis->del('Self_tree_class');
if ($result===false) {
return $this->apiReturn(10003,'删除缓存失败');
}
return $this->apiReturn(0,'删除缓存成功');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\AuthPriceModel;
use App\Model\ClassifyAttrModel;
use App\Model\CodeModel;
use App\Model\ExamineModel;
use App\Model\GoodsModel;
use App\Model\RedisModel;
use App\Model\SampleClassModel;
use App\Model\SampleModel;
use App\Model\SelfBrandModel;
use App\Model\SelfClassifyModel;
use App\Model\SelfFinancialClassifyModel;
use App\Model\SupplierChannelModel;
use App\Model\UnitModel;
use App\Model\UploadLogModel;
use App\Model\UserInfoModel;
use Illuminate\Http\Request;
use DB;
class ClassWebController extends Controller
{
public function Entrance(Request $request, $id='index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
//分类列表
private function SelfClassify($request)
{
$Model=new SelfClassifyModel();
$ClassifyList=$Model->SelfClassifyList();
$Redis=new RedisModel();
$this->data['CalssCache'] = $Redis->get('Self_tree_class');
$this->data['ClassifyList'] = $ClassifyList;
return $this->view('自营分类管理');
}
//新增/编辑分类
private function SaveSelfClassify($request)
{
$SelfClassifyModel=new SelfClassifyModel();
$SelfClassifyList=$SelfClassifyModel->SelfClassifyList();
$info=$SelfClassifyModel->SelfClassifyInfo();
$AttrListName=[];
$AttrList=[];
if (!empty($info['class_id'])) {
$AttrModel=new ClassifyAttrModel();
$AttrListName=$SelfClassifyModel->HDCustom($info['class_id']);
$AttrList=$AttrModel->ClassifyAttrList();
if (is_array($AttrList) && count($AttrList)>0) {
foreach ($AttrList as $k=>$v) {
if ($v['is_name']==2) {
$AttrListName[]=$v;
}
}
}
foreach ($AttrListName as $k=>$v) {
if ($v['is_name']!==2) {
unset($AttrListName[$k]);
}
}
$AttrListName=arraySequence($AttrListName, 'name_sort');
}
$this->data['SelfClassifyList'] = $SelfClassifyList;
$this->data['info'] = $info;
$this->data['AttrList'] = $AttrList;
$this->data['AttrListName'] = $AttrListName;
return $this->view('选择分类');
}
private function SaveClassifyAttr($request, $id, $viewid)
{
$Model=new ClassifyAttrModel();
$AttrList=$Model->SaveClassifyAttr();
$data=[
'title'=>'新增编辑自营分类',
'id'=>$id,
'AttrList'=>$AttrList
];
return view($viewid, $data);
}
private function SetupIsName($request)
{
$GoodsModel=new GoodsModel();
$ClassCount=$GoodsModel->where('class_id2', '=', $request->input('class_id'))->count();
$Prompt='该分类下有'.$ClassCount.'个商品,预计后台任务需要处理'.ceil($ClassCount/500).'分钟,请谨慎操作';
$this->data['Prompt'] = $Prompt;
return $this->view('自定义商品名称规则设置');
}
private function AuthList($request, $id, $viewid)
{
$data=[
'title'=>'自定义商品名称规则设置',
'id'=>$id,
];
return view($viewid, $data);
}
private function SelfClassifySetRule($request, $id, $viewid)
{
$UserModel=new UserInfoModel();
$admin=$UserModel->UserList();
$data=[
'title'=>'分类规则设置记录',
'id'=>'UploadWhereList',
'NoGoodsList'=>true,
'LogType'=>8,
'admin'=>$admin,
'status'=>Config('field.UploadStatus'),
];
return view($viewid, $data);
}
private function ExportSelfGoodsLog($request, $id, $viewid)
{
$UserModel=new UserInfoModel();
$admin=$UserModel->UserList();
$data=[
'title'=>'分类规则设置记录',
'id'=>'UploadWhereList',
'NoGoodsList'=>true,
'LogType'=>9,
'admin'=>$admin,
'status'=>Config('field.UploadStatus'),
];
return view($viewid, $data);
}
/**
* [taxClassify 税务分类数据获取]
* @param Request $request [description]
* @param [type] $id [description]
* @param [type] $viewid [description]
* @return [type] [description]
*/
private function taxClassify($request)
{
$db = new SelfFinancialClassifyModel();
$infos = $db->where('status', 1)->where('level', 3)->select('classify_name', 'classify_sn', 'classify_parent_sn')->get()->toArray();
$this->data['list'] = $infos;
$this->data['into'] = 'no';
return $this->view('税务分类列表');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\CodeModel;
use App\Model\RedisModel;
use Illuminate\Http\Request;
use DB;
class CodeApiController extends Controller
{
public function Entrance(Request $request, $id)
{
return $this->$id($request, $id);
}
private function ApiintraCodeList($request)
{
$collert = $request->only(['code_id','admin_id','limit']);
$map =[];
if (!empty($collert['code_id'])) {
$map[] = ['code_id','=',$collert['code_id']];
}
if (!empty($collert['admin_id'])) {
$map[] = ['admin_id','=',$collert['admin_id']];
}
if (empty($collert['limit'])) {
$limit = 10;
} else {
$limit = $collert['limit'];
}
$Model = new CodeModel();
$list = $Model->CodeList($map, $limit);
return $this->apiReturn(0, 'ok', $list);
}
private function ApiUnbundlingCode($request)
{
$code_id=$request->input('code_id');
$type=$request->input('type');
if (empty($code_id) || $code_id<10000) {
return $this->apiReturn(10001, '解绑失败');
}
$CodeModel = new CodeModel();
if ($type=='admin' || $type=='user') {
$update['update_time']=time();
if ($type=='admin') {
$update['admin_id']=0;
}
if ($type=='user') {
$update['user_id']=0;
}
$return=$CodeModel->where('code_id', $code_id)->update($update);
if (!$return) {
return $this->apiReturn(10002, '解绑失败');
}
} else {
return $this->apiReturn(10002, '解绑失败');
}
$redis=new RedisModel();
$redis->hdel('intracode', $code_id);
return $this->apiReturn(0, '解绑成功');
}
//绑定内部编码
private function ApiBindingCode($request)
{
$Field = ['code_id','mobile','admin_id'];
$collert=$request->input();
$collert = TrimX($collert, true, $Field);
$CodeModel = new CodeModel();
if (!empty($collert['mobile'])) {
$map['mobile']=$collert['mobile'];
unset($collert['mobile']);
$return_user=DB::connection('web')
->table('user_main')
->where($map)
->select('user_id')
->first();
if (empty($return_user['user_id'])) {
return $this->apiReturn(10003, '不存在前台账号'.$map['mobile']);
}
$find_user=$CodeModel
->where('user_id', $return_user['user_id'])
->select('code_id')
->first();
$find_user=(array)$find_user;
if (!empty($find_user['code_id'])) {
return $this->apiReturn(10003, '前台账号'.$map['mobile'].'已经绑定编号'.$find_user['code_id']);
}
$collert['user_id']=$return_user['user_id'];
}
$collert['update_time']=time();
if (!empty($collert['code_id'])) {
$redis=new RedisModel();
$redis->hdel('intracode', $collert['code_id']);
$return=$CodeModel
->where('code_id', $collert['code_id'])->update($collert);
if (!$return && $return!=0) {
return $this->apiReturn(10001, '绑定失败');
}
} else {
$collert['create_time']=time();
$return=$CodeModel
->insertGetId($collert);
if (!$return) {
return $this->apiReturn(10002, '新增失败');
}
}
return $this->apiReturn(0, '绑定成功');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class CodeController extends Controller
{
}
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $data;
protected function errhtml($errcode, $errinfo, $goUrl='')
{
$data = [
'errcode' => $errcode,
'errinfo' => $errinfo,
'url' => $goUrl
];
return view('errors.error', $data);
}
protected function view($title = '')
{
$this->data['title'] = $title;
return view('web', $this->data);
}
protected function apiReturn($errcode = 0, $errmsg = 'OK', $data = '')
{
return apiReturn($errcode, $errmsg, $data);
}
}
<?php
namespace App\Http\Controllers;
use App\Model\SelfBrandModel;
use Illuminate\Http\Request;
class InquiryApiController extends Controller
{
public function Entrance(Request $request, $id)
{
return $this->$id($request, $id);
}
//品牌列表
private function SelfBrandList($request)
{
$Arr=['brand_name','brand_id','status','brand_area'];
$collert = $request->only($Arr);
$limit = $request->input('limit',10);
$collert = TrimX($collert, true, $Arr);
$map=[];
foreach ($collert as $k=>$v) {
if ($k=='brand_name') {
$map[]=['brand_name','like',trim($v).'%'];
} else {
$map[]=[$k,'=',trim($v)];
}
}
$Model=new SelfBrandModel();
$data = $Model->ApiSelfBrandList($map, $limit);
return $this->apiReturn(0, 'ok', $data);
}
//新增/编辑品牌
private function ApiSaveSelfBrand($request)
{
$Model=new SelfBrandModel();
$collert=$request->only(['brand_id','brand_name','brand_logo','brand_brief','main_product','brand_desc','brand_area','status']);
$Arr=['brand_id','brand_name','brand_logo','brand_brief','main_product','brand_desc','brand_area','status'];
$collert=TrimX($collert, false, $Arr);
if (empty($collert)) {
return $this->apiReturn(10001,'缺少必须参数');
}
$Find=$Model->ApiGetBrandByName($collert['brand_name']);
if (!empty($collert['brand_id'])) {
if ($Find && $Find['brand_id'] != $collert['brand_id']) {
return $this->apiReturn(10002, '已经存在该品牌');
}
}
$result = $Model->ApiSaveSelfBrand($collert);
if(!$result){
return $this->apiReturn(10003, '保存失败');
}
return $this->apiReturn(0, '保存成功');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\SelfBrandModel;
use Illuminate\Http\Request;
class InquiryWebController extends Controller
{
public function Entrance(Request $request, $id='index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
private function InquiryList($request)
{
return $this->view('用户询价列表');
}
private function SaveSelfBrand($request)
{
$Model=new SelfBrandModel();
$info=$Model->BrandInfo($request->input('brand_id'));
$BrandArea=config('field.BrandArea');
$this->data['BrandArea'] = $BrandArea;
$this->data['info'] = $info;
return $this->view('新增编辑自营品牌');
}
}
<?php
namespace App\Http\Controllers;
use App\Jobs\GoodsLog;
use App\Model\AuthPriceModel;
use App\Model\SelfBrandModel;
use App\Model\UploadLogModel;
use Illuminate\Http\Request;
class PriceApiController extends Controller
{
public function Entrance(Request $request, $id)
{
return $this->$id($request, $id);
}
//价格列表
private function ApiAuthList($request)
{
$Arr = ['goods_name', 'goods_id', 'add_time', 'status', 'p', 'limit'];
$collert = $request->only($Arr);
$collert = TrimX($collert, true, $Arr);
$Model = new AuthPriceModel();
$data = $Model->ApiAuthPriceList($collert);
return $this->apiReturn(0, 'ok', $data);
}
//修改价格
private function ApiSaveAuthPrice($request)
{
$Arr = ['id', 'purchases', 'price_cn'];
$collert = $request->only($Arr);
$collert = TrimX($collert, true, $Arr);
if (empty($collert['id'])) {
return $this->apiReturn(10001, 'ID参数缺失');
}
if (empty($collert['purchases']) || !is_array($collert['purchases'])) {
return $this->apiReturn(10002, '没有提交价格');
}
foreach ($collert['purchases'] as $k => $v) {
if (!empty($collert['price_cn'][$k])) {
$info[] = [
'purchases' => $v,
'price_cn' => $collert['price_cn'][$k],
'price_us' => 0,
];
}
}
if (empty($info)) {
return $this->apiReturn(10003, '没有上传价格');
}
$Model = new AuthPriceModel();
$result = $Model->ApiSaveAuthPrice($collert, $info);
if (!$result) {
return $this->apiReturn(10003, '保存失败');
}
return $this->apiReturn(0, '保存成功');
}
//审核价格
public function ApiAuthPrice($request)
{
$Arr = ['id', 'status'];
$collert = $request->only($Arr);
$collert = TrimX($collert, true, $Arr);
if (empty($collert['id']) || !is_array($collert['id'])) {
return $this->apiReturn(10001, '没有可审核的数据');
}
if (empty($collert['status'])) {
return $this->apiReturn(10002, '缺少审核状态');
}
$userId = $request->user->userId;
$Model = new AuthPriceModel();
$AuthPrices = [];
//检查数据
foreach ($collert['id'] as $k => $v) {
$AuthPrice = $Model->ApiGetAuthPrice($v);
if (!$AuthPrice) {
return $this->apiReturn(20003, '审核单' . $v . '不存在');
}
$AuthPrice = $AuthPrice->toArray();
if (empty($AuthPrice['ladder_price'])) {
return $this->apiReturn(20004, '审核单' . $v . '没有价格');
}
if (empty($AuthPrice['brand_id'])) {
return $this->apiReturn(20007, 'ID为' . $AuthPrice['goods_id'] . '的商品制造商信息未完善,不能通过审核');
}
if (empty($AuthPrice['class_id2'])) {
return $this->apiReturn(20008, 'ID为' . $AuthPrice['goods_id'] . '的商品分类信息未完善,不能通过审核');
}
//获取检查完毕的价格单数据集合,给model使用
$AuthPrices[$v] = $AuthPrice;
}
$collert['user_id'] = $userId;
$result = $Model->ApiAuthPrice($collert, $AuthPrices);
if (!$result) {
return $this->apiReturn(20006, '调价审核单状态更新失败');
}
return $this->apiReturn(0, '审核成功');
}
//自营批量上传列表
public function ApiUploadGoods()
{
$Model = new UploadLogModel();
$data = $Model->UploadLog();
return $this->apiReturn(0, '成功', $data);
}
//推送价格审核
public function ApiPushAuthPrice($request)
{
$Arr = ['cost', 'goods_id', 'purchases', 'price_cn'];
$collert = $request->only($Arr);
$collert = TrimX($collert, true, $Arr);
if (empty($collert['goods_id'])) {
return $this->apiReturn(10001, '缺少参数');
}
foreach ($collert['purchases'] as $k => $v) {
$v = (int)$v;
if (empty($v) || empty((float)$collert['price_cn'][$k])) {
return $this->apiReturn(10002, '有阶梯为空或者价格填写错误');
}
}
$collert['user_id'] = $request->user->userId;
$Model = new AuthPriceModel();
$result = $Model->ApiPushAuthPrice($collert);
if (!$result) {
return $this->apiReturn(20001, '推送调价审核单失败');
}
return $this->apiReturn(0, '推送调价审核单成功');
}
//批量上传价格
public function ApiUploadPrice($request)
{
$Verification = ServiceTime($request->route('key'));
if ($Verification !== true) {
$this->apiReturn(10006, '本服务' . $Verification . 's内仅能提交一次,请稍后');
}
$collert = $request->only('file');
$collert['user_id'] = $request->user->userId;
$ext = $collert['file']->getClientOriginalExtension();
if ($ext != 'csv') {
$this->apiReturn(10001, '上传格式错误');
}
$Model = new UploadLogModel();
$result = $Model->ApiUploadPrice($collert);
if (!$result) {
$this->apiReturn(10003,'上传失败');
}
return $this->apiReturn(0,'上传成功,请等待系统自动处理');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\AuthPriceModel;
use App\Model\SelfBrandModel;
use Illuminate\Http\Request;
class PriceWebController extends Controller
{
public function Entrance(Request $request, $id = 'index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id,
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
private function AuthList($request)
{
$status = Config('field.BrandStatus');
$BrandArea = config('field.BrandArea');
$this->data['status'] = $status;
$this->data['BrandArea'] = $BrandArea;
return $this->view('价格审核列表');
}
private function SaveAuthPrice($request)
{
$collert = $request->only('id', 'now_price');
$collert = TrimX($collert, true, ['id', 'now_price']);
$Model = new AuthPriceModel();
$info = $Model->ConfirmPriceInfo($collert);
$this->data['info'] = $info;
return $this->view('修改价格');
}
private function AuthPriceUploadLog($request)
{
$this->data['id'] = 'UploadGoods';
$this->data['NoGoodsList'] = true;
$this->data['LogType'] = 6;
return $this->view('价格审核单上传记录');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class TemplateController extends Controller
{
public function Entrance(Request $request, $id = 'index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id,
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
private function TemplateList($request)
{
$name = $request->input('name');
if (!empty($name)) {
return response()->download(storage_path('app/Template/' . $name), $name);
}
$list = [
// '批量上传SKU' => 'UploadSkuV1.0.0.csv',
// '自营批量上传素材(图片/pdf/简短描述/供应商库存/内部编码/静态成本)' => 'UploadSourceV1.3.0.csv',
'自营批量价格处理' => 'UploadpriceV1.0.0.csv',
// '批量上传品牌' => 'UploadBrandV1.0.0.xls',
// '批量上传分类' => 'UploadClassV1.0.0.csv',
// '自营报价上传' => 'self_offer_templetV1.0.0.xlsx',
// '自营样片上传' => 'sample_templet.v1.0.0.xlsx',
];
foreach ($list as $k => $v) {
$size = Storage::lastModified('Template\\' . $v);
unset($list[$k]);
$list[] = [
'describe' => $k,
'file_name' => $v,
'time' => date('Y-m-d H:i', $size),
];
}
$this->data['FileList'] = $list;
return $this->view('模板下载');
}
}
<?php
namespace App\Http\Controllers;
use App\Model\AuthPriceModel;
use App\Model\SelfBrandModel;
use App\Model\UploadLogModel;
use Illuminate\Http\Request;
class UploadLogWebController extends Controller
{
public function Entrance(Request $request, $id = 'index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id,
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
private function DownSkuFile($request)
{
$name=$request->input('name');
$Model = new UploadLogModel();
$perm=perm($request->user->userId, 'DownSkuFile');
$result = $Model->LogInfo($name);
if ($perm===false) {
if ($result) {
$result=(array)$result;
if ($result['admin_id']!=$request->user->userId) {
$data=[
'errcode'=>403,
'errinfo'=>'鉴权失败',
'url'=>Config('perm.go_url')
];
return view('errors.error', $data);
}
} else {
$data=[
'errcode'=>404,
'errinfo'=>'文件不存在',
'url'=>Config('perm.go_url')
];
return view('errors.error', $data);
}
}
$result['file_name']=json_decode($result['file_name'], true);
empty($result['file_name']['down']) ? $url=$result['file_name']['upload']:$url=$result['file_name']['down'];
header('Location:'.$url);
exit();
}
}
<?php
namespace App\Http\Controllers;
use App\Model\AuthPriceModel;
use App\Model\ClassifyAttrModel;
use App\Model\CodeModel;
use App\Model\ExamineModel;
use App\Model\GoodsModel;
use App\Model\RedisModel;
use App\Model\SampleClassModel;
use App\Model\SampleModel;
use App\Model\SelfBrandModel;
use App\Model\SelfClassifyModel;
use App\Model\SupplierChannelModel;
use App\Model\UnitModel;
use App\Model\UploadLogModel;
use App\Model\UserInfoModel;
use Illuminate\Http\Request;
use DB;
class WebController extends Controller
{
public function Entrance(Request $request, $id='index')
{
if ($request->path() == '/') {
$path = 'web/index';
} else {
$path = $request->path();
}
$this->data = [
'menus' => $request->menus,
'header' => $request->user->header,
'username' => $request->user->email,
'useremail' => $request->user->email,
'uri' => '/' . $path,
'id' => $id
];
return $this->$id($request);
}
public function __call($method, $parameters)
{
return $this->errhtml('Not', '没有这个页面');
}
public function index(){
return $this->view('首页');
}
public function intraCode($request)
{
$CodeModel =new CodeModel();
$this->data['UserList'] = $CodeModel->where('admin_id', '>', 0)
->join('user_info', 'lie_intracode.admin_id', '=', 'user_info.userId')
->pluck('name', 'admin_id')->toArray();
return $this->view('内部编码管理');
}
private function HandleCode($request)
{
$code_id=$request->input('code_id');
$info=[];
//提取未绑定得管理员
$UserInfoModel = new UserInfoModel();
$all_admin=$UserInfoModel->where('status', 0)
->select('name', 'email', 'status', 'userId')->get()->toArray();
$CodeModel = new CodeModel();
$bin_code=$CodeModel
->where('admin_id', '>', 0)->select()
->pluck('code_id', 'admin_id')->toArray();
foreach ($all_admin as $k=>$v) {
if (!empty($bin_code[$v['userId']])) {
unset($all_admin[$k]);
}
}
if (!empty($code_id) && $code_id!=0) {
$info=$CodeModel->where('code_id', $code_id)->first();
if ($info) {
$info = $info->toArray();
$info=$CodeModel->info($info);
}
}
$this->data['info'] = $info;
$this->data['all_admin'] = $all_admin;
return $this->view('新增/编辑内部编码');
}
private function OfferList($request)
{
return $this->view('报价列表');
}
private function saveSample($request)
{
$sampleClassModel = new SampleClassModel();
$map = [
'status'=>1
];
$sampleClassInfo = $sampleClassModel->sampleClassList($map);
$this->data['classList'] = empty($sampleClassInfo['data']) ? [] : $sampleClassInfo['data'];
//查找样片信息
$id = $request->input('id');
$sampleModel = new SampleModel();
$list = $sampleModel->sampleList(['id'=>$id, 1]);
$this->data['info'] = reset($list['data']);
return $this->view('编辑样片');
}
private function SampleManage($request){
$sampleClassModel = new SampleClassModel();
$map = [
'status'=>1
];
$sampleClassInfo = $sampleClassModel->sampleClassList($map);
$this->data['classList'] = empty($sampleClassInfo['data']) ? [] : $sampleClassInfo['data'];
return $this->view('自营样片管理');
}
private function SampleClass(){
return $this->view('样片分类列表');
}
private function saveSampleClass($request){
if(!empty($request->input('id'))){
$sampleClassModel = new SampleClassModel();
$list = $sampleClassModel->sampleClassList($request->all(), 1);
$this->data['info'] = reset($list['data']);
}
return $this->view('编辑样片分类');
}
//自营列表页
private function GoodsList($request)
{
$SupplierModel=new SupplierChannelModel();
$SupplierList=$SupplierModel->SupplierListArr(1);
$ClassifyModel=new SelfClassifyModel();
$ClassifyList=$ClassifyModel->SelfClassifyList();
$Status=Config('field.SELFSTATUS');
$this->data['SupplierList'] = $SupplierList;
$this->data['ClassifyList'] = $ClassifyList;
$this->data['Status'] = $Status;
return $this->view('自营商品列表');
}
//新增编辑商品
private function SaveGoods($request)
{
$GoodsModel=new GoodsModel();
$info=$GoodsModel->GoodsInfo();
if ($info) {
$AuthModel=new AuthPriceModel();
$InAuth=$AuthModel->where('goods_id', '=', $info['goods_id'])->where('status', '=', 1)->select('id')->first();
if ($InAuth) {
$info['InAuth']=true;
}
}
$ClassifyModel=new SelfClassifyModel();
$ClassifyList=$ClassifyModel->SelfClassifyList();
$SupplierChanneModel=new SupplierChannelModel();
$SupplierList=$SupplierChanneModel->SupplierListArr(1, true);
$UnitModel=new UnitModel();
$GoodsUnit=$UnitModel->GoodsUnitAll('goods_unit');
$GoodsPacking=$UnitModel->GoodsUnitAll('packing');
$AttrListName=[];
if (!empty($info['class_id2'])) {
$AttrModel=new ClassifyAttrModel();
$AttrListName=$ClassifyModel->HDCustom($info['class_id2']);
$AttrList=$AttrModel->ClassifyAttrList($info['class_id2']);
if (is_array($AttrList) && count($AttrList)>0) {
foreach ($AttrList as $k=>$v) {
if ($v['is_name']==2) {
$AttrListName[]=$v;
}
}
}
foreach ($AttrListName as $k=>$v) {
if ($v['is_name']!==2) {
unset($AttrListName[$k]);
}
}
$AttrListName=arraySequence($AttrListName, 'name_sort');
}
//填补阶梯价到5
if(empty($info['ladder_price'])) $info['ladder_price'] = [];
if(count($info['ladder_price'])<5) $info['ladder_price']=array_pad($info['ladder_price'],5,'');
$PickType=Config('field.PickType');
$this->data['info'] = $info;
$this->data['SelfClassifyList'] = $ClassifyList;
$this->data['SupplierList'] = $SupplierList;
$this->data['GoodsUnit'] = $GoodsUnit;
$this->data['GoodsPacking'] = $GoodsPacking;
$this->data['PickType'] = $PickType;
$this->data['AttrListName'] = $AttrListName;
return $this->view('新增/编辑自营商品');
}
private function ExamineList($request, $id, $viewid)
{
$UserModel=new UserInfoModel();
$UserInfo=$UserModel->UserList();
$data=[
'title'=>'入库审核',
'id'=>$id,
'UserInfo'=>$UserInfo
];
return view($viewid, $data);
}
private function SaveExaminePrice($request, $id, $viewid)
{
$Model=new ExamineModel();
$info=$Model->ConfirmPriceInfo();
$data=[
'title'=>'入库审核',
'id'=>$id,
'info'=>$info
];
return view($viewid, $data);
}
private function UploadGoods($request, $id, $viewid)
{
$UserModel=new UserInfoModel();
$admin=$UserModel->UserList();
$ClassifyModel=new SelfClassifyModel();
$ClassifyList=$ClassifyModel->SelfClassifyList();
$data=[
'title'=>'批量上传',
'id'=>$id,
'admin'=>$admin,
'status'=>Config('field.UploadStatus'),
'ClassifyList'=>$ClassifyList
];
return view($viewid, $data);
}
private function DownloadClassTemplate()
{
$Model=new UploadLogModel();
$data=$Model->DownClassTemplate();
if (!$data) {
$data=[
'errcode'=>403,
'errinfo'=>'模板生成失败',
'url'=>Config('perm.go_url')
];
return view('errors.error', $data);
}
}
private function UploadGoodsFile($request, $id, $viewid)
{
$SuModel=new SupplierChannelModel();
$Supplier=$SuModel->SupplierListArr(1);
$data=[
'title'=>'批量上传',
'id'=>$id,
'Supplier'=>$Supplier
];
return view($viewid, $data);
}
//选择品牌
private function Choice_brand($request)
{
$map=$request->input('brand_name');
$type=$request->input('type');
if (empty($type)) {
$type=1;
}
$db= DB::connection('self')->table('brand')->where('status', '1');
if ($map) {
$db=$db->where('brand_name', 'like', $map.'%');
}
$list=$db->select('brand_name', 'brand_id')->paginate(48);
$this->data['list'] = $list;
$this->data['type'] = $type;
$this->data['into'] = 'no';
return $this->view('选择品牌');
}
private function AuthPriceUploadLog($request, $id, $viewid)
{
$data=[
'title'=>'价格审核单上传记录',
'id'=>'UploadGoods',
'NoGoodsList'=>true,
'LogType'=>6
];
return view($viewid, $data);
}
}
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
// \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
// \App\Http\Middleware\TrimStrings::class,
// \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// \App\Http\Middleware\TrustProxies::class,
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\CheckLogin::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
],
'menu' => [
\App\Http\Middleware\Menu::class
],
'api' => [
\App\Http\Middleware\JsonpCallback::class
],
'WmsApi'=>[
\App\Http\Middleware\WmsVerification::class,
],
'ThirdApi'=>[
\App\Http\Middleware\ThirdApiVerification::class,
]
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
<?php
namespace App\Http\Middleware;
use App\Model\RedisModel;
use App\Model\UserInfoModel;
use Closure;
use App\Http\Output;
use App\Http\Error;
use Config;
use DB;
class CheckLogin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$userId = $request->cookie('oa_user_id');
$skey = $request->cookie('oa_skey');
$isApi = false;
$pos = strpos($request->path(), 'api/');
if ($pos === 0)
$isApi = true;
$login = Config::get('website.login');
if (!$userId || !$skey || (string)((int)$userId) != $userId || !preg_match('/^[a-zA-Z0-9]+$/', $skey)) {
if ($isApi)
return ["errcode" => 401, "errmsg" => "没有登录"];
return redirect($login['login'] . '?redirect=' . urlencode($request->url()));
}
$cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $skey;
$rsp=curl($login['check'],'',false,false,$cookie);
if (!$rsp) {
if ($isApi)
return ['errcode' =>10001, 'errmsg' => '鉴权失败'];
abort(500);
}
$ret = json_decode($rsp);
if ($ret->retcode != 0) {
if ($isApi)
return ["errcode" => $ret->retcode, "errmsg" => $ret->errMsg];
return redirect($login['login'] . '?redirect=' . urlencode($request->url()));
}
$user = $ret->data;
$Redis=new RedisModel();
$UserInfo=$Redis->get('user_userinfo_'.$user->userId);
$user->code='';
if(!$UserInfo){
$code=DB::connection()->table('lie_intracode')->where('admin_id',$user->userId)->select('code_id')->first();
if(!empty($code['code_id'])) $user->code=(object)$code;
$User=new UserInfoModel();
$UserName=$User->where('userId','=',$user->userId)->select('name')->first()->toArray();
$user->UserName=empty($UserName['name'])?$user->email:$UserName['name'];
$Redis->set('user_userinfo_'.$user->userId,json_encode(['code'=>$user->code,'UserName'=>$user->UserName]));
$Redis->expire('user_userinfo_'.$user->userId,60*5);
}else{
$UserInfo=json_decode($UserInfo,true);
$user->code=(object)$UserInfo['code'];
$user->UserName=empty($UserInfo['UserName'])?$user->email:$UserInfo['UserName'];
}
$user->header = $request->cookie('oa_header');
$request->user = $user;
return $next($request);
}
}
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}
<?php
namespace App\Http\Middleware;
use Closure;
use App\Http\Output;
use App\Http\Controllers\LoginController;
use App\Http\Error;
use Config;
class JsonpCallback
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$callback = $request->input('callback', null);
$result = $next($request);
if (!$callback)
return $result;
if (strpos($request->path(), 'api/') !== 0)
return $result;
if (!preg_match('/^[_A-Za-z0-9]+$/', $callback))
return $result;
if (is_array($result)) {
$result = $callback . '(' . json_encode($result) . ')';
} else {
$result->setContent($callback . '(' . $result->content() . ')');
}
return $result;
}
}
<?php
namespace App\Http\Middleware;
use Closure;
class Menu
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$isApi = $request->ajax();
$user = $request->user;
//处理权限和菜单
$permArr = config('perm.perm');
$action = $request->route('key');
empty($action) && $action = 'Dashboard';
//获取菜单
if(!$isApi){
$menuconfig = json_decode(curl($permArr['menuUrl'].$permArr['menuId']));
if(empty($menuconfig->data)){
return $this->view('error','菜单生成错误,请联系技术');
}else $menuconfig = $menuconfig->data;
$menus = !in_array($request->user->userId,$permArr['adminGroup']) ?
menu($menuconfig,$request->user->userId) : $menuconfig;
if(empty($menus))
return $this->view('Auth','没有访问权限',$permArr['goUrl']);
$request->menus = $menus;
}
if(!in_array($user->userId,$permArr['adminGroup']) && $action!='Dashboard'){//不是超级管理员
$perm=perm($request->user->userId,$action);
if($perm!==true){
if($isApi)
return apiReturn(10001,'没有权限');
return $this->view('Auth','没有访问权限',$permArr['goUrl']);
}
}
return $next($request,$action);
}
private function view($errcode,$errinfo,$goUrl=''){
$data=[
'errcode'=>$errcode,
'errinfo'=>$errinfo,
'url'=>$goUrl
];
return view('errors.error', $data);
}
}
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
}
}
<?php
namespace App\Http\Middleware;
use App\Model\RedisModel;
use Closure;
use Request;
class ThirdApiVerification
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$data=Request::only(['data','timestamp','appid','token']);
$Redis=new RedisModel();
$key=json_decode($Redis->hget('Self_third_supplier_appid',$data['appid']),true);
if(empty($key['key']) || (empty($key['supplier_id']) and empty($key['supplier_com_id']))) return $this->Export([10005,'该用户尚未授权访问']);//没有这个用户的
$request->appid=$data['appid'];
if($data['token']!=='lxap10086123456'){
$data=ExcessDecrypt($data,$key['key']);
if($data[0]!==0) return $this->Export($data);
$request->Wmsdata=$data[2];
}else $request->Wmsdata=$data['data'];
$request->key=$key['key'];
$request->supplier_id = empty($key['supplier_id']) ? 0 : $key['supplier_id'];
$request->pool_supplier_id = empty($key['supplier_com_id']) ? 0 : $key['supplier_com_id'];
return $next($request);
}
private function Export($errcode=0,$errmsg='成功',$data='',$total=''){
ErrorLog($errcode,$errcode,$errmsg);
if(is_array($errcode)){
echo json_encode(['errcode'=>$errcode[0],'errmsg'=>$errcode[1],'data'=>!empty($errcode[2])?$errcode[2]:'','total'=>!empty($errcode[3])?$errcode[3]:'']);
}else{
echo json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data,'total'=>$total]);
}
exit();
}
}
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'password',
'password_confirmation',
];
}
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array
*/
protected $proxies;
/**
* The current proxy header mappings.
*
* @var array
*/
protected $headers = [
Request::HEADER_FORWARDED => 'FORWARDED',
Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];
}
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}
<?php
namespace App\Http\Middleware;
use Closure;
use App\Http\Output;
use App\Http\Error;
use Config;
use DB;
use Request;
class WmsVerification
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$data=Request::all();
$token=$data['token'];
if(empty($data['data']) || empty($data['timestamp']) || empty($token)) return $this->Export(40001,'参数缺失');
$result = WMSVerification($data,$token);
if($result !== true) return $this->Export(40002,'签名验证失败',$result);
$request->Wmsdata=json_decode(urldecode($data['data']),true);
return $next($request);
}
private function Export($errcode=0,$errmsg='成功',$data='',$total=''){
return json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data,'total'=>$total]);
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use DB;
use Artisan;
class Batches extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id)
{
$this->log_id=$id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$map['up_id'] = $this->log_id;
$log = DB::connection('spu')
->table('lie_upload_log')
->where($map)
->first();
$log = (array)$log;
$log['log'] = json_decode($log['log'], true);
if (($log['status'] != 0 && $log['status'] != 1) || empty($log['encoded'])) {
$LogInfo = $log['log'];
$LogInfo[] = date('Y-m-d H:i', time()) . '任务状态错误,跳过此次任务';
$data['log'] = json_encode($LogInfo);
$data['update_time'] = time();
$this->log($map, $data, true);
} else {
$LogInfo = $log['log'];
$LogInfo[] = date('Y-m-d H:i', time()) . '开始执行任务';
$data['status'] = 1;
$data['log'] = json_encode($LogInfo);
$data['update_time'] = time();
$this->log($map, $data, false);
}
$dbmap['supplier_id'] = $log['supplier_id'];
$dbmap['encoded'] = $log['encoded'];
if (!empty($log['remark'])) {
$dbmap[] = ['canal', '=', $log['remark']];
}
if (!empty($log['file_name'])) {
$log['file_name'] = json_decode($log['file_name'], true);
if (is_array($log['file_name'])) {
$dbmap[] = ['update_time', '>=', $log['file_name']['start_time']];
$dbmap[] = ['update_time', '<=', $log['file_name']['end_time']];
}
}
$update['goods_status'] = 3;
for ($dbcode = 0; $dbcode < 10; $dbcode++) {
$db = DB::connection('sku_' . $dbcode);
for ($table = 0; $table < 10; $table++) {
$update['update_time'] = time();
$db->table('lie_sku_' . $table)->where($dbmap)->update($update);
}
}
$LogInfo[] = date('Y-m-d H:i', time()) . '任务完成';
$data['status'] = 2;
$data['log'] = json_encode($LogInfo);
$data['update_time'] = time();
$this->log($map, $data, false);
$exitCode = Artisan::call('sku:redis', [
'param1' => $log['supplier_id'], 'param2' => 0, 'param3' => 'z', 'code' => $log['encoded']
]);
}catch (\Exception $e){
SendAlarm($e);
}
}
private function log($map,$data,$ext){
$db=DB::connection('spu')
->table('lie_upload_log')
->where($map)
->update($data);
if($ext==true){
$this->delete();
}
if($db){
return false;
}else{
return true;
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class DeletePoolGoods extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $map;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($map='')
{
$this->map=$map;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if(empty($this->map)) $Map=['update_time'=>''];
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\StockUpModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ExportIckeyIndex extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $BrandName;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($BrandName,$log_id)
{
$this->BrandName=$BrandName;
$this->log_id=$log_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$Model=new StockUpModel();
$map['brand_name/condition']=$this->BrandName;
$map['limit']=100;
$count=10;
$LogModel = new UploadLogModel();
$LogInfo = $LogModel->LogInfo($this->log_id);
$Log = json_decode($LogInfo['log'], true);
$LogModel->UpdateLogArr($this->log_id, '开始处理任务', 1, $Log);
$filename='ExportIcKey-'.date('YmdHis').'.csv';
$x = fopen(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$filename,'w');
$title=['商品型号','制造商(品牌)','猎芯网总搜索次数','ickey总搜索次数','ickey交易次数'];
foreach ($title as $k=>$v) $res[$k]=iconv('utf-8','GBK//IGNORE',$v);
fputcsv($x,$res);
$Fail=true;
for ($i=1;$i<$count+1;$i++){
$map['p']=$i;
$result=$Model->SoApiIndex($map);
if(!isset($result['error_code']) || $result['error_code']!==0) break;
if(ceil($result['data']['total']/$map['limit'])>30) $count=30;//计算最大分页数
else $count=ceil($result['data']['total']/$map['limit']);
foreach($result['data']['list'] as $k=>$v){
$res=[$v['goods_name'],$v['brand_name'],$v['lx_search_count'],$v['ickey_search_count'],$v['ickey_trade_count']];
foreach ($res as $kk=>$vv) $res[$kk]=iconv('utf-8','GBK//IGNORE',$vv);
fputcsv($x,$res);
$Fail=false;
}
}
if($Fail===true){
$LogModel->UpdateLogArr($this->log_id, '没有数据可以下载', 3, $Log);
return false;
}
$UploadFileModel = new UploadLogModel();
$Url = $UploadFileModel->SaveDownFile($filename);
if (!$Url) {
SendDingUrl('生成失败', $LogInfo['admin_id'], '云汉指数数据包');
$LogModel->UpdateLogArr($this->log_id, '上传表格失败', 3, $Log);
return false;
} else {
$data['file_name']=$Url;
SendDingUrl($Url, $LogInfo['admin_id'], '云汉指数数据包下载地址');
$LogModel->UpdateLogArr($this->log_id, '任务完成', 2, $Log,$data);
return true;
}
}catch(\Exception $e){
SendAlarm($e);
$LogModel->UpdateLogArr($this->log_id, '任务失败,请联系技术查看原因', 3, $Log);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\BrandModel;
use App\Model\GoodsModel;
use App\Model\RedisModel;
use App\Model\ResourceModel;
use App\Model\SelfBrandModel;
use App\Model\SelfClassifyModel;
use App\Model\SupplierChannelModel;
use App\Model\UnitModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use RedisDB;
class ExportSelfGoods extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($UserID)
{
$this->log_id=$UserID;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$LogModel = new UploadLogModel();
$LogInfo = $LogModel->LogInfo($this->log_id);
$Log = json_decode($LogInfo['log'], true);
$collert = json_decode($LogInfo['remark'], true);
$LogModel->UpdateLogArr($this->log_id, '开始处理任务', 1, $Log);
$GoodsModel = new GoodsModel();
$count = 100;
$fieldArr = ['goods_id', 'goods_name', 'brand_id','class_id1', 'class_id2', 'barcode', 'mpq', 'packing', 'encap', 'cost',
'new_cost','static_cost', 'stock', 'wait_stock','supplier_stock', 'supplier_id','self_supplier_type','encoded', 'ladder_price',
'pick_type','status', 'goods_images', 'pdf', 'sku_name', 'goods_brief'];
$filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.csv';
$x = fopen(storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $filename, 'w');
$Arr = ['SKUID', '型号', '制造商','一级分类', '二级分类', '原厂条码', '标准包装量(MPQ)', '包装方式', '封装规则', '成本', '最新成本','静态成本', '库存',
'待入库数量', '供应商库存', '供应商', '自采标记', '内部编码', '是否有价格', '拣货方式', '状态', '图片地址', 'PDF地址', '商品标题', '简短描述',
'阶梯','人民币售价','利润率','库龄','总销量'];
foreach ($Arr as $k => $v) {
$Arr[$k] = iconv('utf-8', 'gbk//IGNORE', $v);
}
fputcsv($x, $Arr);
$BrandList = new SelfBrandModel();
$UnitModel = new UnitModel();
$SupplierModel = new SupplierChannelModel();
$Redis = new RedisModel();
$PickType = Config('field.PickType');
$ClassModel = new SelfClassifyModel();
$ClassIDArr = $ClassModel->OBAllClassIDName();
//处理条件
$map = [];
$Arr = ['goods_id', 'goods_name', 'sku_name', 'supplier_id', 'brand_id', 'goods_type', 'status', 'class_id1', 'class_id2', 'start_time',
'end_time', 'encoded', 'wait_stock', 'noprice', 'stock', 'nostock', 'noprice'];
$collert = TrimX($collert, true, $Arr);
if (!empty($collert['start_time']) || !empty($collert['end_time'])) {
if (!empty($collert['start_time']) && !empty($collert['end_time'])) {
$map[] = ['update_time', '>=', strtotime($collert['start_time'])];
$map[] = ['update_time', '<=', strtotime($collert['end_time'])];
unset($collert['start_time']);
unset($collert['end_time']);
}
if (!empty($collert['start_time']) && empty($collert['end_time'])) {
$map[] = ['update_time', '>', strtotime($collert['start_time'])];
unset($collert['start_time']);
}
if (empty($collert['start_time']) && !empty($collert['end_time'])) {
$map[] = ['update_time', '<', strtotime($collert['end_time'])];
unset($collert['end_time']);
}
}
if (!empty($collert['goods_name'])) {
$map[] = ['goods_name', 'like', '%' . $collert['goods_name'] . '%'];
unset($collert['goods_name']);
}
if (!empty($collert['sku_name'])) {
$map[] = ['sku_name', 'like', '%' . $collert['sku_name'] . '%'];
unset($collert['sku_name']);
}
if (!empty($collert['wait_stock']) && $collert['wait_stock'] == 'true') {
$map[] = ['wait_stock', '>', 0];
}
if (!empty($collert['nostock']) && $collert['nostock'] == 'true') {
$map[] = ['stock', '=', 0];
}
if (!empty($collert['stock']) && $collert['stock'] == 'true') {
$map[] = ['stock', '>', 0];
}
if (!empty($collert['noprice']) && $collert['noprice'] == 'true') {
$map[] = ['ladder_price', '', ''];
}
if (isset($collert['wait_stock'])) unset($collert['wait_stock']);
if (isset($collert['nostock'])) unset($collert['nostock']);
if (isset($collert['stock'])) unset($collert['stock']);
if (isset($collert['noprice'])) unset($collert['noprice']);
if (is_array($collert)) {
foreach ($collert as $k => $v) {
$map[] = [$k, '=', $v];
}
}
$UrlModel = new ResourceModel();
$self_supplier_type = config('Goods.self_supplier_type');
$self_goods_status = config('field.SELFSTATUS');
for ($p = 1; $p < $count + 1; $p++) {
$list = $GoodsModel->where($map)->select($fieldArr)->paginate(1000, ['*'], '', $p)->toArray();
$count = $list['last_page'];
foreach ($list['data'] as $k => $v) {
$v['brand_id'] = $BrandList->HDBrandName($v['brand_id'], $Redis);
$v['packing'] = $UnitModel->OBUnitInfo($v['packing'], $Redis);
$v['supplier_id'] = $SupplierModel->ObSupplierName($v['supplier_id']);
$v['ladder_price'] = empty($v['ladder_price']) ? '没有价格' : '有价格';
$v['pick_type'] = empty($PickType[$v['pick_type']]) ? '无' : $PickType[$v['pick_type']];
$v['class_id2'] = empty($ClassIDArr[$v['class_id2']]) ? '未知' : $ClassIDArr[$v['class_id2']];
$v['class_id1'] = empty($ClassIDArr[$v['class_id1']]) ? '未知' : $ClassIDArr[$v['class_id1']];
$goods_images = $UrlModel->GetResourceInfoById($v['goods_images'], ['url']);
$v['goods_images'] = empty($goods_images['url']) ? '' : $goods_images['url'];
$pdf = $UrlModel->GetResourceInfoById($v['pdf'], ['url']);
$v['pdf'] = empty($pdf['url']) ? '' : $pdf['url'];
$v['status'] = empty($self_goods_status[$v['status']]) ? '未知' : $self_goods_status[$v['status']];
//处理自采标记
$v['self_supplier_type'] = empty($self_supplier_type[$v['self_supplier_type']]) ? '未知' : $self_supplier_type[$v['self_supplier_type']];
$Arr = [];
foreach ($fieldArr as $k1 => $v1) $Arr[$k1] = $v[$v1];
$ladder='';$price='';
$profit = '';
if(!empty($list['data'][$k]['ladder_price'])){//处理价格
$ladder_price=json_decode($list['data'][$k]['ladder_price'],true);
if(is_array($ladder_price)){
foreach ($ladder_price as $lak => $prv){
$ladder .=$prv['purchases'].";\r\n";
$price .=$prv['price_cn'].";\r\n";
if(!empty($prv['price_cn']) && !empty($v['cost']) && $v['cost'] != 0){
$profit .= round(($prv['price_cn']-$v['cost'])/$v['cost']*100, 2).'%'.";\r\n";
}else{
$profit .= '无'.";\r\n";
}
}
}
}
$Arr[]=$ladder;
$Arr[]=$price;
$Arr[]=$profit;
foreach ($Arr as $k => $v) {
$Arr[$k] = iconv('utf-8', 'gbk//IGNORE', $v);
}
fputcsv($x, $Arr);
}
}
$UploadFileModel = new UploadLogModel();
$Url = $UploadFileModel->SaveDownFile($filename);
if (!$Url) {
SendDingUrl('生成失败', $LogInfo['user_id'], '自营商品列表下载地址');
$LogModel->UpdateLogArr($this->log_id, '生成表格失败', 3, $Log);
} else {
SendDingUrl($Url, $LogInfo['user_id'], '自营商品列表下载地址');
$LogModel->UpdateLogArr($this->log_id, '任务完成', 2, $Log);
}
}catch(\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\BrandMappingModel;
use App\Model\BrandModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class GRBrandMP extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $UserID;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($UserID)
{
$this->UserID=$UserID;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$BrandModel = new BrandModel();
$MappingModel = new BrandMappingModel();
$BrandList = $BrandModel->HDBrandAll();
$filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.csv';
$x = fopen(storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $filename, 'w');
$BrandArr = ['品牌ID', '品牌名字', '映射品牌'];
foreach ($BrandArr as $k => $v) {
$BrandArr[$k] = iconv('utf-8', 'gbk//IGNORE', $v);
}
fputcsv($x, $BrandArr);
foreach ($BrandList as $k => $v) {
$BrandArr = [];
$Arr = $MappingModel->BrandInfoLXID($v['brand_id']);
$BrandArr[] = $v['brand_id'];
$BrandArr[] = $v['brand_name'];
if (is_array($Arr)) {
foreach ($Arr as $k1 => $v1) {
$BrandArr[] = $v1;
}
}
foreach ($BrandArr as $k => $v) {
$BrandArr[$k] = iconv('utf-8', 'gbk//IGNORE', $v);
}
fputcsv($x, $BrandArr);
}
$LogModel = new UploadLogModel();
$url = $LogModel->SaveDownFile($filename);
if (!$url) {
SendDingUrl('生成失败', $this->UserID);
} else {
SendDingUrl($url, $this->UserID);
}
}catch(\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
abstract class Job
{
/*
|--------------------------------------------------------------------------
| Queueable Jobs
|--------------------------------------------------------------------------
|
| This job base class provides a central location to place any logic that
| is shared across all of your jobs. The trait included with the class
| provides access to the "onQueue" and "delay" queue helper methods.
|
*/
use Queueable;
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\FtpDownload;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class PoolDateHD extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $frequency;
private $Name;
private $DelayJob;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($Name='youxin',$frequency=1,$DelayJob=false)
{
$this->frequency=$frequency;
$this->Name=$Name;
$this->DelayJob=$DelayJob;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$Model=new FtpDownload($this->Name,$this->frequency,$this->DelayJob);
try{
$Model->YouXin();
}catch (\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\ClassifyAttrModel;
use App\Model\GoodsModel;
use App\Model\SelfBrandModel;
use App\Model\SelfClassifyModel;
use App\Model\UnitModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use RedisDB;
class SelfGoodsNameRule extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $ClassID;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($log_id)
{
$this->log_id=$log_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try{
$map['up_id']=$this->log_id;
$LogModel=new UploadLogModel();
$LogInfo=$LogModel->LogInfo($this->log_id);
$Log = json_decode($LogInfo['log'],true);
if(empty($LogInfo['encoded'])){
return $LogModel->UpdateLogArr($this->log_id,'没有查找到分类ID,任务停止',3,$Log);
}else{
$this->ClassID=$LogInfo['encoded'];
$LogModel->UpdateLogArr($this->log_id,'开始处理任务',1,$Log);
}
$ClassModel=new SelfClassifyModel();
$AttrListName=$ClassModel->HDCustom($this->ClassID,true);
$ClassInfo=$ClassModel->where('class_id','=',$this->ClassID)->select('class_name')->first();
if(!$ClassInfo) {
return $LogModel->UpdateLogArr($this->log_id,'没有查找到分类',3,$Log);
};
$ClassInfo=$ClassInfo->toArray();
$AttrModel=new ClassifyAttrModel();
$classAttr=$AttrModel->where('class_id','=',$this->ClassID)->where('is_name','=',2)->orderBy('name_sort','desc')->select('attr_name','attr_id','name_sort')->get();
if(!empty($classAttr)){
$classAttr=$classAttr->toArray();
foreach ($classAttr as $k=>$v){
$AttrListName[]=$v;
}
}
$AttrListName=arraySequence($AttrListName,'name_sort');
$GoodsModel=new GoodsModel();
$su=0;
$fail=0;
$count=2;
$Redis=RedisDB::connection();
$BrandModel=new SelfBrandModel();
$UnitModel=new UnitModel();
for ($p=1;$p<$count;$p++){
$list=$GoodsModel->where('class_id2','=',$this->ClassID)->select('goods_name','brand_id','goods_id','attrs','encap','packing')->paginate(1000, ['*'], '', $p)->toArray();
foreach ($list['data'] as $k=>$v){
$count=$list['last_page']+1;
$attrs=json_decode($v['attrs'],true);
$SkuName='';
foreach ($AttrListName as $k1=>$v1){
switch ($v1['attr_id']){
case 'custom1':
$SkuName .=empty($ClassInfo['class_name'])?'':$ClassInfo['class_name'].' ';
break;
case 'custom2':
$BrandName=$BrandModel->HDBrandName($v['brand_id'],$Redis);
$SkuName .=empty($BrandName)?'':$BrandName.' ';
break;
case 'custom3':
$SkuName .=empty($v['encap'])?'':$v['encap'].' ';
break;
case 'custom4':
$SkuName .=empty($v['goods_name'])?'':$v['goods_name'].' ';
break;
case 'custom5':
$packing=$UnitModel->OBUnitInfoAlias($v['packing'],$Redis);
$SkuName .=empty($packing)?'':$packing.' ';
break;
default:
if(!empty($attrs)){
foreach ($attrs as $k2=>$v2){
if($v1['attr_name']==$v2['attr_name']){
$SkuName .=empty($v2['attr_value'])?'':$v2['attr_value'].' ';
break;
}
}
}
}
}
$result=$GoodsModel->where('goods_id','=',$v['goods_id'])->update(['sku_name'=>$SkuName,'update_time'=>time()]);
if(!$result){
$fail++;
}else{
$GoodsModel->UpdateGoodsRedis($v['goods_id'],$Redis,true);//推送到redis和wms
$su++;
}
}
}
return $LogModel->UpdateLogArr($this->log_id,'处理完成,该分类下有'.$list['total'].'个商品,成功'.$su.'个,失败'.$fail.'个',2,$Log);
}catch (\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\SelfBrandModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Model\GoodsModel;
use App\Model\UnitModel;
use App\Model\SelfClassifyModel;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use DB;
use RedisDB;
class SelfGoodsPush extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $class_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id)
{
$this->class_id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$class_id = $this->class_id;
$SelfClassifyModel = new SelfClassifyModel();
$BrandModel = new SelfBrandModel();
$UnitModel = new UnitModel();
$connection = new AMQPStreamConnection(env('RABBITMQ_HOST'), env('RABBITMQ_PORT'), env('RABBITMQ_LOGIN'), env('RABBITMQ_PASSWORD'), env('RABBITMQ_VHOST')); // 创建连接
$channel = $connection->channel();
$queue_name = env('RABBITMQ_QUEUE'); // SKU分类相关信息通过接口平台传到WMS
$channel->queue_declare($queue_name, false, true, false, false);
$db = DB::connection('self');
$infos = $db->table('self_classify')->where('class_id',$class_id)->select('class_id','class_name','parent_id','status', 'is_dc')->first();
if ($infos) {
$produce_info['class_id'] = $class_id;
$produce_info['class_name'] = $infos['class_name'];
$produce_info['status'] = $infos['status'];
$produce_info['parent_id'] = $infos['parent_id'];
$produce_info['is_dc'] = $infos['is_dc'];
$produce_if['data'] = $produce_info;
$produce_if['type'] = 'skuclass.syn';
$message = new AMQPMessage(json_encode($produce_if), array('content_type' => 'text/plain', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT));
$channel->basic_publish($message, '', $queue_name);
}else{
return false;
}
// 根据class_id & 属于自营0或3 查符合条件的sku list 一条一条入rbmq
$fieldArr = ['other_attrs', 'pick_type', 'barcode', 'goods_id','goods_type','supplier_id','brand_id','class_id2','goods_name','status',
'encoded','encap','packing','goods_unit','goods_images','pdf','goods_brief','batch_sn','moq','mpq',
'mpq_unit','sku_name'];
$count = 100;
$i = 0;
for ($p = 1; $p < $count + 1; $p++) {
$list = $db->table('goods')->select($fieldArr)->where('class_id2', $class_id)->paginate(1000,['*'],'',$p)->toArray();
foreach ($list['data'] as $k => $info) { // SKU相关信息通过接口平台传到WMS(生产入队)
$pick_type = $info['pick_type'];
$barcode = $info['barcode'];
$other_attrs = $info['other_attrs'];
$other_attrs = json_decode($other_attrs, true);
$gross_wegiht = isset($other_attrs['gross_wegiht']) ? $other_attrs['gross_wegiht'] : 0;
// $length = isset($other_attrs['length']) ? $other_attrs['length'] : 0;
$SelfClassifyInfo = $SelfClassifyModel->SelfClassifyInfo($info['class_id2']);
$is_dc = $SelfClassifyInfo['is_dc'];
$brand_name = $BrandModel->HDBrandName($info['brand_id']);
$goods_unit = $UnitModel->OBUnitInfo($info['goods_unit']);
$mpq_unit = $UnitModel->OBUnitInfo($info['packing']);
$PickType = Config('field.PickType');
$enqueue_info['goods_id'] = $info['goods_id'];
$enqueue_info['brand_name'] = $brand_name;
$enqueue_info['class_id2'] = $info['class_id2'];
$enqueue_info['goods_type'] = $info['goods_type'];
$enqueue_info['supplier_id'] = $info['supplier_id'];
$enqueue_info['goods_name'] = $info['goods_name'];
$enqueue_info['encap'] = $info['encap'];
$enqueue_info['goods_unit'] = $goods_unit;
$enqueue_info['sku_name'] = $info['sku_name'];
$enqueue_info['mpq_unit'] = $mpq_unit;
$enqueue_info['mpq'] = $info['mpq'];
$enqueue_info['pick_type'] = $PickType[$pick_type]; // 1:裁剪 2:称重 3:计数
$enqueue_info['barcode'] = $barcode;
// $enqueue_info['length'] = $length;
$enqueue_info['gross_wegiht'] = changeUnit($gross_wegiht, 'g');
$enqueue_info['status'] = 1; // 暂时传1 from yyc 180508
$enqueue_info['is_dc'] = $is_dc;
$pushdata['data'] = $enqueue_info;
$pushdata['type'] = 'sku.syn';
$message = new AMQPMessage(json_encode($pushdata), array('content_type' => 'text/plain', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT));
$channel->basic_publish($message, '', $queue_name); // 推送消息
}
$count = $list['last_page'];
}
$channel->close();
$connection->close();
}catch (\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\RedisModel;
use App\Model\SupplierModel;
use App\Model\SupplierRatioModel;
use App\Model\UserInfoModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendNotice extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $type;private $url;private $node;private $pre;private $Info;
private $UserModel;private $RedisModel;private $User;private $AdminId;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($type=0,$node=0,$AdminID=0,$url='')
{
$this->type=$type;
$this->url=$url;
$this->node=$node;
$this->pre ='Self_SendNotice';
if(Config('website.data')=='footstone.ichunt.net'){
$RobotArr=[
'PoolSupplier'=>Config('website.Feer_Robot_Url'),//联营供应商修改通知
];
}else{
$RobotArr=[
'PoolSupplier'=>'https://oapi.dingtalk.com/robot/send?access_token=92917a6e090a8a39832c4843a579d6c6f9dfecc46fa275f8753ddee2b4399045',//联营供应商修改通知
];
}
$this->AdminId=$AdminID;
$this->Info=[
1=>[
'title'=>'供应商修改通知',
'key'=>'save_supplier',
'Url'=>$RobotArr['PoolSupplier']
],
2=>[
'title'=>'系数调整通知',
'key'=>'save_coefficient',
'Url'=>$RobotArr['PoolSupplier']
],
3=>[
'title'=>'附加费调整通知',
'key'=>'save_extra',
'Url'=>$RobotArr['PoolSupplier']
]
];
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try{
$this->UserModel=new UserInfoModel();
$this->RedisModel=new RedisModel();
if($this->AdminId===0) $this->User='系统';
else $this->User=$this->UserModel->GetUserInfoName($this->AdminId);
if($this->type===0) return SendRobot($this->url,$this->node);//为0时,直接发送通知
else{
$Action=$this->Info[$this->type]['key'];
return $this->$Action();
}
}catch (\Exception $e){
SendAlarm($e);
dispatch((new SendNotice($this->type,$this->node,$this->AdminId,$this->url))->delay(3600));
}
}
private function save_supplier(){//修改供应商
try{
$Action=$this->Info[$this->type]['key'];
$History=$this->RedisModel->hget($this->pre,$Action.'_'.$this->node);//取出历史数据
$SupplierModel=new SupplierModel();
$Info=$SupplierModel->where('lie_supplier.supplier_id','=',$this->node)
->join('lie_supplier_extra','lie_supplier.supplier_id','=','lie_supplier_extra.supplier_id')
->select('type_id','supplier_name','lie_supplier.status','ad_text','supplier_logo','hk_delivery','cn_delivery','ad_url','sort','supplier_nickname')->first();//取出现有数据
if(!$Info) return false;
$Info=$Info->toArray();
$Arr=['type_id'=>'类别','supplier_name'=>'名字','status'=>'状态','ad_text'=>'宣传文案','supplier_logo'=>'Logo','hk_delivery'=>'香港货期',
'cn_delivery'=>'大陆货期','ad_url'=>'运营链接','sort'=>'排序','supplier_nickname'=>'昵称'];
$TypeID=Config('Goods.PoolTypeID');
$Status=Config('Goods.PoolStatus');
$Info['type_id']=empty($TypeID[$Info['type_id']])?$Info['type_id']:$TypeID[$Info['type_id']];
$Info['status']=empty($Status[$Info['status']])?$Info['status']:$Status[$Info['status']];
$jsonInfo=json_encode($Info);
if($History!=$jsonInfo){//不全等时才发通知
$History=json_decode($History,true);
$SendInfo=$this->Info[$this->type]['title']."\n";
foreach ($Info as $k=>$v){
$HistoryInfo=empty($History[$k])?' 未知':$History[$k];
if($HistoryInfo!=$v) $SendInfo .=$Arr[$k].' : '.$HistoryInfo.' -> '.$v."\n";
}
$SendInfo .='供应商 : '.$Info['supplier_name']."\n";
$SendInfo .='操作人: '.$this->User;
$this->RedisModel->hset($this->pre,$Action.'_'.$this->node,$jsonInfo);//更新历史记录
SendRobot($this->Info[$this->type]['Url'],$SendInfo);
}
}catch (\Exception $e){
SendAlarm($e);
dispatch((new SendNotice($this->type,$this->node,$this->AdminId,$this->url))->delay(3600));
}
}
private function save_extra(){//调整附加费
try{
$Action=$this->Info[$this->type]['key'];
$History=$this->RedisModel->hget($this->pre,$Action.'_'.$this->node);//取出历史数据
$SupplierModel=new SupplierModel();
$Info=$SupplierModel->where('lie_supplier.supplier_id','=',$this->node)->select('supplier_name','supp_extend_fee')->first();//取出现有数据
if(!$Info) return false;
$Info=$Info->toArray();
$jsonInfo=json_decode($Info['supp_extend_fee'],true);
if($History!=$Info['supp_extend_fee']){//不全等时才发通知
$FeeInfo=json_decode($History,true);
$SendInfo=$this->Info[$this->type]['title']."\n";
if($FeeInfo){
$SendInfo .='原附加费:不满'.$FeeInfo[0]['max'].'收取'.$FeeInfo[0]['price']."运费\n";
}
$SendInfo .='新附加费:不满'.$jsonInfo[0]['max'].'收取'.$jsonInfo[0]['price']."运费\n";
$SendInfo .='供应商 : '.$Info['supplier_name']."\n";
$SendInfo .='操作人: '.$this->User;
$this->RedisModel->hset($this->pre,$Action.'_'.$this->node,$Info['supp_extend_fee']);//更新历史记录
SendRobot($this->Info[$this->type]['Url'],$SendInfo);
}
}catch (\Exception $e){
SendAlarm($e);
dispatch((new SendNotice($this->type,$this->node,$this->AdminId,$this->url))->delay(3600));
}
}
private function save_coefficient(){//调整系数
try{
$SupplierModel=new SupplierRatioModel();
$Info=$SupplierModel->where('id','=',$this->node)
->join('lie_supplier','lie_supplier_ratio.supplier_id','=','lie_supplier.supplier_id')
->select('supplier_name','cn','hk','extra_ratio','ratio','is_default','lie_supplier_ratio.status')->first();//取出现有数据
if(!$Info) return false;
$Info=$Info->toArray();
$is_default = $Info['is_default'] ===1 ? '否' : '是';
$status = $Info['status'] ===1 ? '否' : '是';
$SendInfo=$this->Info[$this->type]['title']."\n";
$SendInfo .='供应商 : '.$Info['supplier_name']."\n";
$SendInfo .='系数ID : '.$this->node."\n";
$SendInfo .='人民币利润 : '.$Info['cn']."\n";
$SendInfo .='美金利润 : '.$Info['hk']."\n";
$SendInfo .='原始币种转美金汇率 : '.$Info['extra_ratio']."\n";
$SendInfo .='美金转人民币汇率 : '.$Info['ratio']."\n";
$SendInfo .='是否默认 : '.$is_default."\n";
$SendInfo .='是否禁用 : '.$status."\n";
$SendInfo .='操作人: '.$this->User;
SendRobot($this->Info[$this->type]['Url'],$SendInfo);
}catch (\Exception $e){
SendAlarm($e);
dispatch((new SendNotice($this->type,$this->node,$this->AdminId,$this->url))->delay(3600));
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\ClassifyAttrModel;
use App\Model\GoodsModel;
use App\Model\RedisModel;
use App\Model\SelfBrandModel;
use App\Model\SelfClassifyModel;
use App\Model\SelfFinancialClassifyModel;
use App\Model\UnitModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class ThirdGoodsInfo extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $log_id;
private $RobotUrl='https://oapi.dingtalk.com/robot/send?access_token=40582b05286b67331874c8b9d5273261e4148812c49870ff9ca93ed907dddc93';
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id)
{
$this->log_id=$id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try{
$LogModel=new UploadLogModel();
$LogInfo = $LogModel->LogInfo($this->log_id);
$Log = json_decode($LogInfo['log'], true);
$data=json_decode($LogInfo['remark'],true);
$LogModel->UpdateLogArr($this->log_id, '开始处理任务', 1, $Log);
$GoodsModel=new GoodsModel();
$list=$GoodsModel->whereIn('goods_id',$data['SkuArr'])->select('goods_name','class_id2','brand_id','goods_id','attrs','encap','packing')
->get()->toArray();
$su=[];
$Fail=[];
$Redis=new RedisModel();
$UnitModel=new UnitModel();
$BrandModel=new SelfBrandModel();
$AttrModel=new ClassifyAttrModel();
$ClassModel=new SelfClassifyModel();
$FinancialModel=new SelfFinancialClassifyModel();
foreach ($list as $k=>$v){
//处理图片与pdf,简短描述
if(!empty($v['brand_id'])){//有品牌时才去处理
$Find=$GoodsModel->where('brand_id','=',$v['brand_id'])->whereIn('goods_type',[0,3])->where('goods_name','=',$v['goods_name'])
->where('goods_id','!=',$v['goods_id'])->select('goods_brief','goods_images','pdf','attrs')->first();
if($Find){
$Find=$Find->toArray();
foreach ($Find as $kk=>$vv) if(empty($v)) unset($Find[$k]);
$Find['update_time']=time();
if(!empty($Find)) $GoodsModel->where('goods_id','=',$v['goods_id'])->update($Find);
if(!empty($Find['attrs']))$v['attrs']=$Find['attrs'];
}
}
if(empty($v['class_id2'])){
$Fail[$v['goods_id']]='没有分类';
continue;
}//没有分类时,不生成skuname
$attrs=json_decode($v['attrs'],true);
$SkuName='';
if(empty($AttrListName[$v['class_id2']])){
$AttrListName[$v['class_id2']]=$ClassModel->HDCustom($v['class_id2'],true);
if(empty($AttrListName[$v['class_id2']])){
$Fail[$v['goods_id']]='没有获取到分类命名规则';
continue;
}
}
if(empty($ClassInfo[$v['class_id2']])){
$ClassInfo[$v['class_id2']]=$ClassModel->where('class_id','=',$v['class_id2'])->select('class_name','financial_classify_id')->first();
if(!$ClassInfo[$v['class_id2']]){
$Fail[$v['goods_id']]='没有查到分类信息';
continue;
}else $ClassInfo[$v['class_id2']]=$ClassInfo[$v['class_id2']]->toArray();
}
if(empty($classAttr[$v['class_id2']])){
$classAttr[$v['class_id2']]=$AttrModel->where('class_id','=',$v['class_id2'])->where('is_name','=',2)->orderBy('name_sort','desc')->select('attr_name','attr_id','name_sort')->get();
if(!empty($classAttr[$v['class_id2']])){
$classAttr[$v['class_id2']]=$classAttr[$v['class_id2']]->toArray();
foreach ($classAttr[$v['class_id2']] as $kk=>$vv){
$AttrListName[$v['class_id2']][]=$vv;
}
}
}
if(!empty($AttrListName[$v['class_id2']])){
$AttrListName[$v['class_id2']]=arraySequence($AttrListName[$v['class_id2']],'name_sort');
}else{
$Fail[$v['goods_id']]='没有skuname生成信息';
continue;
}
foreach ($AttrListName[$v['class_id2']] as $k1=>$v1){
switch ($v1['attr_id']){
case 'custom1':
$SkuName .=empty($ClassInfo[$v['class_id2']]['class_name'])?'':$ClassInfo[$v['class_id2']]['class_name'].' ';
break;
case 'custom2':
$BrandName=$BrandModel->HDBrandName($v['brand_id'],$Redis);
$SkuName .=empty($BrandName)?'':$BrandName.' ';
break;
case 'custom3':
$SkuName .=empty($v['encap'])?'':$v['encap'].' ';
break;
case 'custom4':
$SkuName .=empty($v['goods_name'])?'':$v['goods_name'].' ';
break;
case 'custom5':
$packing=$UnitModel->OBUnitInfoAlias($v['packing'],$Redis);
$SkuName .=empty($packing)?'':$packing.' ';
break;
default:
if(!empty($attrs)){
foreach ($attrs as $k2=>$v2){
if($v1['attr_name']==$v2['attr_name']){
$SkuName .=empty($v2['attr_value'])?'':$v2['attr_value'].' ';
break;
}
}
}
}
}
//处理税务分类
$upadte=['sku_name'=>$SkuName,'update_time'=>time()];
if(!empty($ClassInfo[$v['class_id2']])){
if(empty($Tax[$ClassInfo[$v['class_id2']]['financial_classify_id']])){
$upadte['tax_classify_name']=$FinancialModel->FindInfo($ClassInfo[$v['class_id2']]['financial_classify_id']);
}else $upadte['tax_classify_name']=$Tax[$ClassInfo[$v['class_id2']]['financial_classify_id']];
}
$result=$GoodsModel->where('goods_id','=',$v['goods_id'])->update($upadte);
if($result) $su[]=$v['goods_id'];
else $Fail[$v['goods_id']]='数据库修改失败';
}
foreach ($list as $k=>$v) $GoodsModel->UpdateGoodsRedis($v['goods_id'],$Redis,true);//推送到redis和wms
$data['su']=$su;
$data['Fail']=$Fail;
$info['remark']=json_encode($data);
return $LogModel->UpdateLogArr($this->log_id, '处理完成,同步商品数量'.count($data['SkuArr']).'个商品,成功'.count($su).'个,失败'.count($Fail).'个', 2,$Log,$info);
}catch (\Exception $e){
SendAlarm($e,$this->RobotUrl);
return $LogModel->UpdateLogArr($this->log_id,'任务失败,出现致命错误,已发出预警',3,$Log);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\RedisModel;
use App\Model\TimingTaskModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class TimingTask extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $jobs;
private $DelayJob;
private $Redis;
private $warningUrl;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($jobs,$DelayJob=false)
{
$this->jobs=$jobs;
$this->DelayJob=$DelayJob;
$this->warningUrl=Config('website.CSWarningRobot');//发出异常警告机器人
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->Redis=new RedisModel();
try{
$TimingTaskModel=new TimingTaskModel();
if($this->DelayJob===true){//验证任务ID
if($this->DelayJob!==true){//第一次提交为true
$redis=$this->Redis->hget('TimingTask',$this->jobs);
if(!$redis || $redis!=$this->DelayJob) return SendRobot('','同步系数汇率任务ID比对失败,终止任务'."\r\n任务ID:$this->DelayJob");
}
$this->Redis->hset('TimingTask',$this->jobs,time());//重置任务ID
//推送一个明天的任务
$Action='Push'.$this->jobs;
$result=$TimingTaskModel->$Action(['job'=>$this->jobs,'DelayJob'=>'true']);
if(!$result) SendRobot('','同步系数汇率任务推送失败,需手动重启');
}
$JobAction=$this->jobs;
$result=$TimingTaskModel->$JobAction();
if(!$result) return SendRobot('','同步系数汇率任务处理失败,需重启');
SendRobot('','系统自动同步系数汇率任务已完成');
return true;
}catch (\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use DB;
use Artisan;
class UpdateSkuTime extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id)
{
$this->log_id=$id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$LogModel = new UploadLogModel();
$LogInfo = $LogModel->LogInfo($this->log_id);
$Log = json_decode($LogInfo['log'], true);
$collert = json_decode($LogInfo['remark'], true);
$LogModel->UpdateLogArr($this->log_id, '开始处理任务', 1, $Log);
$map['supplier_id']=$LogInfo['supplier_id'];
$map['encoded'] = $LogInfo['encoded'];
if(!empty($collert['canal'])) $map['canal']=$collert['canal'];
$map['goods_status']=1;
$count=0;
for ($dbcode = 0; $dbcode < 10; $dbcode++) {
$db = DB::connection('sku_' . $dbcode);
for ($table = 0; $table < 10; $table++) {
$update['update_time'] = time();
$i=$db->table('lie_sku_' . $table)->where($map)->update($update);
$count +=$i;
}
}
$exitCode = Artisan::call('sku:redis', [
'param1' => $LogInfo['supplier_id'], 'param2' => 0, 'param3' => 'z', 'code' => $LogInfo['encoded']
]);
return $LogModel->UpdateLogArr($this->log_id, '任务完成,共更新'.$count.'个sku', 2, $Log);
}catch (\Exception $e){
SendAlarm($e);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use DB;
use Config;
class UploadClass extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($name)
{
$this->log_id=$name;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
echo 1;
$map['up_id']=$this->log_id;
$LogInfo=DB::connection('spu')
->table('lie_upload_log')
->where($map)
->first();
$LogInfo=(array)$LogInfo;
$LogInfo['log']=json_decode($LogInfo['log'],true);
if($LogInfo['status']!=0 && $LogInfo['status']!=1){
$Log=$LogInfo['log'];
$Log[]=date('Y-m-d H:i',time()).'任务状态错误,跳过此次任务';
$data['log']=json_encode($Log);
$data['update_time']=time();
$this->log($map,$data,true);
return false;
}else{
$Log=$LogInfo['log'];
$Log[]=date('Y-m-d H:i',time()).'开始执行任务';
$data['status']=1;
$data['log']=json_encode($Log);
$data['update_time']=time();
$this->log($map,$data,false);
}
empty($LogInfo['file_name']) || $LogInfo['file_name']=json_decode($LogInfo['file_name'],true);
if(empty($LogInfo['file_name']['upload'])){
$data['update_time'] = time();
$Log[] = date('Y-m-d H:i',$data['update_time']).'文件下载出错,任务终止';
$data['log'] = json_encode($Log);
$data['status'] = 3;
$this->UpdateLog($data,true);
return false;
}
echo 2;
$filePath = $LogInfo['file_name']['upload'];
$filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.csv';
$read = fopen($filePath, 'r');
$write = fopen(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$filename,'w');
$count=0;
while (!feof($read)) {
echo 3;
$res = fgetcsv($read);
if(!$res) break;
foreach ($res as $k=>$v){
$res[$k]=iconv('gbk','utf-8',$res[$k]);
}
$count++;
if($count==1){
echo 4;
$title=Config('api.CLASS_TITLE');
//识别表头
foreach ($title as $k=>$v){
if(str_replace(array("\r\n", "\r", "\n"), "", $res[$k])!=$v){
$Log[]=date('Y-m-d H:i',time()).'表头'.$v.'不匹配';
$data['status']=3;
$data['log']=json_encode($Log);
$data['update_time']=time();
$this->log($map,$data,true);
return false;
}
}
$res[-2]='是否成功';$res[-1]='状态描述';
ksort($res);
foreach ($res as $k=>$v){
$res[$k]=iconv('utf-8','gbk',$v);
}
fputcsv($write,$res);
}else{
echo 5;
$data=[];
//处理空行
if(empty($res[0])){
unset($res);
continue;
}
$liexinclassid=0;
$supplier=trim($res[9]);
//查询猎芯分类
if(!empty($res['6']) && !empty($res['7']) && !empty($res['8'])){
$sql='SELECT a.class_id AS cat_id3,b.class_id AS cat_id2,c.class_id AS cat_id1 FROM lie_classify a LEFT JOIN lie_classify b ON a.parent_id = b.class_id LEFT JOIN lie_classify c ON b.parent_id = c.class_id
WHERE a.class_name ="'.trim($res['6']).'" AND b.class_name ="'.trim($res['7']).'" AND c.class_name ="'.trim($res['8']).'"';
$LiexinClass=DB::connection('spu')->select($sql);
if(count($LiexinClass)>0){
$liexinclassid=$LiexinClass[0]['cat_id3'];
}
}
//写分类
$ClassArr=array_splice($res,0,6);
$SaveReturn=$this->parent($ClassArr,$supplier,$liexinclassid);
$res[-2]=$SaveReturn['errcode']?:'未知';
$res[-1]=$SaveReturn['errinfo']?:'未知';
ksort($res);
fputcsv($write,$res);
}
}
$Log[]=date('Y-m-d H:i',time()).'任务完成';
$data['status']=2;
$data['log']=json_encode($Log);
$data['update_time']=time();
$this->log($map,$data,false);
}
private function log($map,$data,$ext){
$db=DB::connection('spu')
->table('lie_upload_log')
->where($map)
->update($data);
if($ext==true){
$this->delete();
}
if($db){
return false;
}else{
return true;
}
}
private function parent($class,$supplier,$liexinclassid){
foreach ($class as $k=>$v){
if(empty($v)){
unset($class[$k]);
}
}
$count=count($class);
$parent_id=0;
foreach ($class as $k=>$v){
$arr=explode('-->',$v);
if(empty($arr[0])){
return array('errcode'=>'失败','errinfo'=>((int)$k+1).'级分类名字不存在');
}
if(empty($arr[1])){
return array('errcode'=>'失败','errinfo'=>((int)$k+1).'级分类ID不存在');
}
$return=DB::connection('spu')
->table('lie_classify_mapping')
->where('supplier_cat_id',trim($arr[1]))
->where('supplier_name',trim($supplier))
->select('cm_id')
->first();
//不存在分类
if(empty($return['cm_id'])){
$save=[
'cm_name'=>trim($arr[0]),
'supplier_name'=>trim($supplier),
'parent_id'=>$parent_id,
'create_time'=>time(),
'status'=>1,
'supplier_cat_id'=>trim($arr[1])
];
if($k==($count-1)){
$save['liexin_class_id']=$liexinclassid;
}
$return=DB::connection('spu')
->table('lie_classify_mapping')
->insertGetId($save);
if(!$return){
return array('errcode'=>'失败','errinfo'=>$arr[0].'新增失败');
}
$parent_id=$return;
}else{
$parent_id=$return['cm_id'];
if($k==($count-1)){
return array('errcode'=>'失败','errinfo'=>'已经存在');
}
}
}
return array('errcode'=>'成功','errinfo'=>'新增成功');
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class UploadFile extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\AuthPriceModel;
use App\Model\GoodsModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Storage;
class UploadPrice extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $log_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id)
{
$this->log_id=$id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try{
$map['up_id']=$this->log_id;
if(empty($map['up_id'])) $this->delete();
$LogModel=new UploadLogModel();
$LogInfo=$LogModel->LogInfo($this->log_id);
if(!is_array($LogInfo)) $this->delete();
$Log = json_decode($LogInfo['log'],true);
if(($LogInfo['status'] !=0 && $LogInfo['status'] !=1)){
return $LogModel->UpdateLogArr($this->log_id,'任务状态错误,跳过此次任务','',$Log);
}else{
$LogModel->UpdateLogArr($this->log_id,'开始执行任务',1,$Log);
}
empty($LogInfo['file_name']) || $LogInfo['file_name']=json_decode($LogInfo['file_name'],true);
$filePath = $LogInfo['file_name']['upload'];
$filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.csv';
$read = fopen($filePath, 'r');
$su=0;
$fail=0;
$count=0;
$AuthModel=new AuthPriceModel();
$GoodsModel=new GoodsModel();
$title[]='SKUID';
for ($i=1;$i<10;$i++){
$title[]='阶梯数量'.$i;
$title[]='人民币价格'.$i;
}
$write = fopen(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$filename,'w');
while (!feof($read)) {
$res = fgetcsv($read);
if (!$res) break;
foreach ($res as $k => $v) {
$res[$k] = iconv('gbk', 'utf-8', $res[$k]);
$res[$k] = trim($res[$k]);
}
$count++;
if ($count == 1) {//处理表头
foreach ($title as $k => $v) {
if ($v != $res[$k]) {
return $LogModel->UpdateLogArr($this->log_id,'表头' . $v . '不匹配',3,$Log);
}
}
$res[-1]='结果';
$this->putcsv($res,$write);
}else{
$info=$res;
$SKUID=$res[0];
unset($res[0]);
if(empty($SKUID)){
$fail++;
$info[-1] = '没有填写SKU';
$this->putcsv($info,$write);
continue;
}
$FindGoods=$GoodsModel->where('goods_id','=',$SKUID)->select('cost')->first();
if(!$FindGoods){
$fail++;
$info[-1] = '没有这个SKUID';
$this->putcsv($info,$write);
continue;
}
$FindGoods=$FindGoods->toArray();
$Price=array_chunk($res,2);
$Price=array_slice($Price,0,9);
$PriceArr=[];
foreach ($Price as $k=>$v){
$v[0]=(int)$v[0];
$v[1]=round($v[1],4);//保留4位小数
if(empty($v[0]) && empty($v[1])){
continue;
}
if(empty($v[0]) || empty($v[1])){
$fail++;
$info[-1] = '价格参数填写错误';
$this->putcsv($info,$write);
continue;
}
$PriceArr[$k]=[
'purchases'=>$v[0],
'price_cn'=>$v[1]
];
}
$PriceArr=arraySequence($PriceArr,'purchases','SORT_ASC');//排序
$update=[
'goods_id'=>$SKUID,
'ladder_price'=>json_encode($PriceArr),
'add_time'=>time(),
'upload_user_id'=>$LogInfo['admin_id'],
'cost'=>$FindGoods['cost'],
'status'=>1
];
$Find=$AuthModel->where('goods_id','=',$SKUID)->where('status','=',1)->select('id')->first();
if($Find){
$Find=$Find->toArray();
$result=$AuthModel->where('id','=',$Find['id'])->update($update);
}else{
$result=$AuthModel->insert($update);
}
if(!$result && $result!==0){
$fail++;
$info[-1] = '新增调价审核单失败';
$this->putcsv($info,$write);
continue;
}else{
$su++;
$info[-1] = '新增调价审核单成功';
$this->putcsv($info,$write);
continue;
}
}
}
$url=$LogModel->SaveDownFile($filename);
if(!$url){
return $LogModel->UpdateLogArr($this->log_id,'结果表格上传失败,请联系技术'.$filename,3,$Log);
}
$data['update_time']=time();
$data['status']=2;
$Log[]=date('Y-m-d H:i',$data['update_time']).'上传成功,成功数量:'.$su.',失败数量:'.$fail.',请下载表格查看具体结果';
$data['log']=json_encode($Log);
$LogInfo['file_name']['down']=$url;
$data['file_name']=json_encode($LogInfo['file_name']);
$LogModel->UpdateLog($this->log_id,$data);
Storage::disk('uploads')->delete($filename);
}catch (\Exception $e){
Log::error(json_encode($e->getMessage()));
SendAlarm($e);
}
}
private function putcsv($res,$write){
foreach ($res as $k => $v) {
$res[$k] = iconv('utf-8', 'gbk', $v);
}
fputcsv($write, $res);
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\config;
class mouser extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $info;
protected $type;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($info,$type='mouser')
{
//
$this->info=$info;
$this->type=$type;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if($this->type=='mouser'){
$redis=Redis::connection();
$return=Handle_Mouser($this->info);
if(empty($return['sku'])){
$return['errcode']=1;
}else{
$return['errcode']=0;
}
$redis->hset('handle_mouser_log',time(),json_encode($return));
}
if($this->type=='upload'){
upload_sku($this->info);
}
}
}
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
No preview for this file type
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
No preview for this file type
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment