123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- declare (strict_types = 1);
- namespace app\bbc\controller;
- use app\admin\model\GoodBasic;
- use app\admin\model\GoodExam;
- use app\admin\model\GoodLadder;
- use app\admin\model\GoodNake;
- use app\admin\model\GoodPlatform;
- use app\admin\model\GoodProof;
- use app\admin\model\Platform;
- use app\model\AccountItem;use think\App;
- use think\Exception;
- use think\facade\Validate;
- class Good extends Base
- {
- public function __construct(App $app) {parent::__construct($app);}
-
- public function list(){
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 15,
- 'cat_id' => '',
- 'good_name' => '',
- 'skucode' => '',
- 'spucode' => '',
- 'start' => '',
- 'end' => '',
- 'is_stock' => '',
- 'good_type' => '',
- 'supplierNo' => '',
- 'companyNo' => '',
- 'creater' => '',
- 'online_creater' => '',
- 'createrid' => '',
- 'status' => '',
- 'platform_code' => '',
- 'platform_type' => 2,
- 'plat_code' => '',
- 'exam_status' => '',
- 'brand_id' => '',
- 'company_name' => '',
- 'create_source' => '',
- 'is_compliance' => '',
- 'relaComNo' => '',
- ],'post','trim');
-
- $where = [['b.is_del', '=', 0]];
- $platfrom =new Platform();
- if ($param['cat_id'] !== '') $where[] = ['a.cat_id', '=', $param['cat_id']];
- if ($param['good_name'] !== '') $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
- if ($param['skucode'] !== '') $where [] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
- if ($param['spucode'] !== '') $where [] = ['b.spucode', 'like', '%' . $param['spucode'] . '%'];
- if ($param['start'] !== '') $where[] = ['b.addtime', '>=', date('Y-m-d H:i:s', strtotime($param['start']))];
- if ($param['end'] !== '') $where[] = ['b.addtime', '<', date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
- if ($param['is_stock'] !== '') $where[] = ['a.is_stock', '=', $param['is_stock']];
- if ($param['good_type'] !== '') $where[] = ['a.good_type', '=', $param['good_type']];
- if ($param['supplierNo'] !== '') $where[] = ['a.supplierNo', '=', $param['supplierNo']];
- if ($param['companyNo'] !== '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
- if ($param['online_creater'] !== '') $where[] = ['b.creater', 'like', '%' . $param['online_creater'] . '%'];
- if ($param['creater'] !== '') $where[] = ['a.creater', 'like', '%' . $param['creater'] . '%'];
- if ($param['createrid'] !== '') $where[] = ['a.createrid', '=', $param['createrid']];
- if ($param['status'] !== '') $where[] = ['a.status', '=', $param['status']];
- if ($param['platform_code'] !== '') $where[] = ['b.platform_code', '=', $param['platform_code']];
- if ($param['plat_code'] !== '') $where[] = ['b.plat_code', 'like', '%' . $param['plat_code'] . '%'];
- if ($param['exam_status'] !== '') $where[] = ['b.exam_status', '=', $param['exam_status']];
- if ($param['create_source'] !== '') $where[] = ['a.create_source', '=', $param['create_source']];
- if ($param['is_compliance'] !== '') $where[] = ['b.is_compliance', '=', $param['is_compliance']];
- if ($param['brand_id'] !== '') $where[] = ['a.brand_id', '=', $param['brand_id']];
- if($param['platform_type'] !== ''){
- $platfromId = $platfrom->where(['platform_type'=>$param['platform_type'],'is_del'=>0])->column('id');
- $where[] = ['b.platform_code', 'in', $platfromId ];
- }
- if($param['relaComNo'] !== '') $where[]=['a.companyNo|a.supplierNo','=', $param['relaComNo']];
- $list = (new GoodPlatform()) ->alias('b')
- ->leftJoin('good a', 'a.spuCode=b.spuCode')
- ->field('b.skuCode,b.platform_code,b.plat_code,b.id as good_id,a.cat_id,a.good_name,a.good_img,b.is_fixed,
- a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.supplierName,a.create_source,
- a.good_unit,a.noble_metal,a.companyNo,a.companyName,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,
- b.exam_status,a.createrid purchase_id,a.creater purchase,a.is_stock,b.is_compliance,b.compliance_remark')
- ->where($where)->order('b.id desc')->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
- $cat =new \app\admin\model\Cat();
- $Brand =new \app\admin\model\Brand();
- $unit =new \app\admin\model\Unit();
- $account = new AccountItem();
- foreach ($list->items() as $item){
- $catinfo= $cat->where(['id'=>$item['cat_id']])->value('search','');
- $item['cat_info'] =explode('_',$catinfo);
- $item['brand_name'] =$Brand->where(['id'=>$item['brand_id']])->value('brand_name','');
- $item['platform_name'] =$platfrom->where(['id'=>$item['platform_code']])->value('platform_name','');
- $item['company_name'] =$account->alias('a')->leftJoin('company_item b','a.itemid=b.id')
- ->where('a.account_id',$item['createrid'])->value('b.name');
- }
- $this->success("获取成功", ['list' => $list->items(), 'count' => $list->total()]);
- }
-
-
- //审核
- public function exam(){
- $post =$this->request->only([
- 'skuCode'=>'', //商品成本编号
- 'exam_status'=>'', //审核状态 1 提交待完善成本 2待审核 3上线完成 4 审核驳回 5 下线完成 6 待bbc上线补录bbc编号 7 bbc驳回
- 'offline_reason'=>'', //下线原因
- 'offline_remark'=>'', //下线备注
- 'plat_code'=>'', //平台订单号
- 'exam_remark'=>'', //审核备注
- 'good_ladder'=>[], //售价阶梯
- 'proof_type'=>'', // 售价凭证类型
- 'proof_url'=>'', // 售价凭证
- ],'post','trim');
- $valide = Validate::rule([
- 'skuCode|商品编号'=>'require|max:255',
- 'exam_status|审核状态'=>'require|number|in:0,1,2,3,4,5,6,7',
- 'offline_reason|线下原因'=>'requireIf:exam_status,5|max:255',
- 'offline_remark|下线备注'=>'requireIf:exam_status,5|max:255',
- 'plat_code|平台商品编码'=>'requireIf:exam_status,3|max:255',
- 'exam_remark|审核备注'=>'max:255',
- 'good_ladder|售价阶梯'=>'requireIf:exam_status,6|array',
- 'proof_type|售价凭证类型'=>'requireIf:exam_status,6|number|gt:0',
- 'proof_url|售价凭证'=>'requireIf:exam_status,6|max:255',
- ]);
- if($valide->check($post)==false) $this->error($valide->getError());
- $goodPlat = new GoodPlatform();
- $goodNake = new GoodNake();
- $platform = $goodPlat->where(['skuCode'=>$post['skuCode'],'is_del'=>0])->findOrEmpty();
- if($platform->isEmpty()) $this->error('未找到商品数据');
-
- if($platform->is_fixed==1){
- //使用实时金价
- $nake=$goodNake->where(['spuCode'=> $platform->spuCode,'is_del'=>0,'nake_fee'=>0])
- ->findOrEmpty();
- if($nake->isEmpty()==false) $this->error('一口价商品请先完善商品成本单价');
- }
- if($post['exam_status']==3){
- $is_exit = $goodPlat
- ->where(['plat_code' =>$post['plat_code'],'is_del' =>0, 'exam_status' =>3])//bbc商品编号唯一不可重复
- ->where('id', '<>', $platform['id'])
- ->findOrEmpty();
- if($is_exit->isEmpty()) $platform->plat_code=$post['plat_code'];
- else $this->error("平台商品编码 {$post['plat_code']} 已存在");
- }
- if($post['exam_status']==5){
- $platform->is_compliance=0;
- $platform->compliance_remark='';
- }
- $before= $platform['exam_status'];
- $platform->exam_status=$post['exam_status'];
- $platform->updatetime=date('Y-m-d H:i:s');
- $createrid= $this->uid;
- $creater= $this->uname;
- $platform->startTrans();
- try {
- $up = $platform->save();
- if($up){
- $data=[
- 'code'=>$platform->skuCode,
- 'exam_status'=>$post['exam_status'],//$exam_status,
- 'type'=>2,
- 'exam_id'=>$createrid,
- 'exam_name'=>$creater,
- 'exam_remark'=>$post['exam_remark'],
- 'addtime'=>date('Y-m-d H:i:s')
- ];
- $inr=(new GoodExam())->save($data);
- if($inr){
- if ($post['exam_status'] == 6) {
- //todo::需要去掉;
- if($post['proof_url']!=''){
- $proof=[
- 'spuCode'=>$platform->spuCode,
- 'proof_type'=>$post['proof_type'],
- 'proof_url'=>$post['proof_url'],
- 'is_del'=>0,
- 'creater'=>$this->uname,
- 'createrid'=>$this->uid,
- 'addtime'=>date('Y-m-d H:i:s'),
- 'updatetime'=>date('Y-m-d H:i:s')
- ];
- GoodProof::create($proof);
- }
-
- if(empty($post['good_ladder']))throw new Exception('商品阶梯价不能为空');
- $goodLadder =new GoodLadder();
- $saveArr=[];
- foreach ($post['good_ladder'] as $value){
- $lemp=[];
- isset($value['id'])?$lemp['id']=$value['id']:$lemp['addtime'] = date('Y-m-d H:i:s');
- $lemp['skuCode']=$platform->spuCode;
- $lemp['min_num'] = $value['min_num'];
- $lemp['max_num'] = 0;
- $lemp['sale_price'] = $value['sale_price'];
- $lemp['market_price'] = $value['market_price'];
- $lemp['market_platform'] = $value['market_platform'];
- $lemp['cost_fee'] = $value['cost_fee'];
- $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
- $lemp['updatetime'] =date('Y-m-d H:i:s');
- $saveArr[]=$lemp;
- }
- $ladderUp = $goodLadder->saveAll($saveArr);
- if($ladderUp==false) throw new Exception('商品阶梯价录入失败');
- }
-
- }else throw new Exception('商品审核失败');
- }else throw new Exception('商品审核失败');
- $platform->commit();
- //流程记录
- $event=[ 'order_type' => 'BBCSX',
- 'order_code' =>$platform->skuCode,//咨询单详情编号
- 'order_id' => $platform->id,
- 'order_status' => 2,
- 'action_process' =>$post['exam_status'],
- 'action_status' => $before,
- 'action_uid' => $this->uid,
- 'action_name' => $this->uname,
- ];
- event('ProcessOrder',$event);
- if($post['exam_status']==5){
- //下线记录
- $enevt=[
- 'spuCode' => $platform->spuCode,
- 'skuCodes' => $platform->skuCode,
- 'type' => 2,
- 'good_name' => (new GoodBasic())->where('spuCode',$platform->spuCode)->value('good_name', ''),
- 'offline_reason' => $post['offline_reason'],
- 'offline_remark' => $post['offline_remark'],
- 'createrid' => $createrid,
- 'creater' => $creater,
- ];
- event('GoodOff',$enevt);
- }
- $this->success('商品审核成功');
- }catch (Exception $e){
- $platform->rollback();
- $this->error($e->getMessage().$e->getLine().$e->getFile());
- }
- }
- }
|