Good.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\bbc\controller;
  4. use app\admin\model\GoodBasic;
  5. use app\admin\model\GoodExam;
  6. use app\admin\model\GoodLadder;
  7. use app\admin\model\GoodNake;
  8. use app\admin\model\GoodPlatform;
  9. use app\admin\model\GoodProof;
  10. use app\admin\model\Platform;
  11. use app\model\AccountItem;use think\App;
  12. use think\Exception;
  13. use think\facade\Validate;
  14. class Good extends Base
  15. {
  16. public function __construct(App $app) {parent::__construct($app);}
  17. public function list(){
  18. $param = $this->request->only([
  19. 'page' => 1,
  20. 'size' => 15,
  21. 'cat_id' => '',
  22. 'good_name' => '',
  23. 'skucode' => '',
  24. 'spucode' => '',
  25. 'start' => '',
  26. 'end' => '',
  27. 'is_stock' => '',
  28. 'good_type' => '',
  29. 'supplierNo' => '',
  30. 'companyNo' => '',
  31. 'creater' => '',
  32. 'online_creater' => '',
  33. 'createrid' => '',
  34. 'status' => '',
  35. 'platform_code' => '',
  36. 'platform_type' => 2,
  37. 'plat_code' => '',
  38. 'exam_status' => '',
  39. 'brand_id' => '',
  40. 'company_name' => '',
  41. 'create_source' => '',
  42. 'is_compliance' => '',
  43. 'relaComNo' => '',
  44. ],'post','trim');
  45. $where = [['b.is_del', '=', 0]];
  46. $platfrom =new Platform();
  47. if ($param['cat_id'] !== '') $where[] = ['a.cat_id', '=', $param['cat_id']];
  48. if ($param['good_name'] !== '') $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
  49. if ($param['skucode'] !== '') $where [] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
  50. if ($param['spucode'] !== '') $where [] = ['b.spucode', 'like', '%' . $param['spucode'] . '%'];
  51. if ($param['start'] !== '') $where[] = ['b.addtime', '>=', date('Y-m-d H:i:s', strtotime($param['start']))];
  52. if ($param['end'] !== '') $where[] = ['b.addtime', '<', date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
  53. if ($param['is_stock'] !== '') $where[] = ['a.is_stock', '=', $param['is_stock']];
  54. if ($param['good_type'] !== '') $where[] = ['a.good_type', '=', $param['good_type']];
  55. if ($param['supplierNo'] !== '') $where[] = ['a.supplierNo', '=', $param['supplierNo']];
  56. if ($param['companyNo'] !== '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  57. if ($param['online_creater'] !== '') $where[] = ['b.creater', 'like', '%' . $param['online_creater'] . '%'];
  58. if ($param['creater'] !== '') $where[] = ['a.creater', 'like', '%' . $param['creater'] . '%'];
  59. if ($param['createrid'] !== '') $where[] = ['a.createrid', '=', $param['createrid']];
  60. if ($param['status'] !== '') $where[] = ['a.status', '=', $param['status']];
  61. if ($param['platform_code'] !== '') $where[] = ['b.platform_code', '=', $param['platform_code']];
  62. if ($param['plat_code'] !== '') $where[] = ['b.plat_code', 'like', '%' . $param['plat_code'] . '%'];
  63. if ($param['exam_status'] !== '') $where[] = ['b.exam_status', '=', $param['exam_status']];
  64. if ($param['create_source'] !== '') $where[] = ['a.create_source', '=', $param['create_source']];
  65. if ($param['is_compliance'] !== '') $where[] = ['b.is_compliance', '=', $param['is_compliance']];
  66. if ($param['brand_id'] !== '') $where[] = ['a.brand_id', '=', $param['brand_id']];
  67. if($param['platform_type'] !== ''){
  68. $platfromId = $platfrom->where(['platform_type'=>$param['platform_type'],'is_del'=>0])->column('id');
  69. $where[] = ['b.platform_code', 'in', $platfromId ];
  70. }
  71. if($param['relaComNo'] !== '') $where[]=['a.companyNo|a.supplierNo','=', $param['relaComNo']];
  72. $list = (new GoodPlatform()) ->alias('b')
  73. ->leftJoin('good a', 'a.spuCode=b.spuCode')
  74. ->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,
  75. a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.supplierName,a.create_source,
  76. a.good_unit,a.noble_metal,a.companyNo,a.companyName,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,
  77. b.exam_status,a.createrid purchase_id,a.creater purchase,a.is_stock,b.is_compliance,b.compliance_remark')
  78. ->where($where)->order('b.id desc')->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
  79. $cat =new \app\admin\model\Cat();
  80. $Brand =new \app\admin\model\Brand();
  81. $unit =new \app\admin\model\Unit();
  82. $account = new AccountItem();
  83. foreach ($list->items() as $item){
  84. $catinfo= $cat->where(['id'=>$item['cat_id']])->value('search','');
  85. $item['cat_info'] =explode('_',$catinfo);
  86. $item['brand_name'] =$Brand->where(['id'=>$item['brand_id']])->value('brand_name','');
  87. $item['platform_name'] =$platfrom->where(['id'=>$item['platform_code']])->value('platform_name','');
  88. $item['company_name'] =$account->alias('a')->leftJoin('company_item b','a.itemid=b.id')
  89. ->where('a.account_id',$item['createrid'])->value('b.name');
  90. }
  91. $this->success("获取成功", ['list' => $list->items(), 'count' => $list->total()]);
  92. }
  93. //审核
  94. public function exam(){
  95. $post =$this->request->only([
  96. 'skuCode'=>'', //商品成本编号
  97. 'exam_status'=>'', //审核状态 1 提交待完善成本 2待审核 3上线完成 4 审核驳回 5 下线完成 6 待bbc上线补录bbc编号 7 bbc驳回
  98. 'offline_reason'=>'', //下线原因
  99. 'offline_remark'=>'', //下线备注
  100. 'plat_code'=>'', //平台订单号
  101. 'exam_remark'=>'', //审核备注
  102. 'good_ladder'=>[], //售价阶梯
  103. 'proof_type'=>'', // 售价凭证类型
  104. 'proof_url'=>'', // 售价凭证
  105. ],'post','trim');
  106. $valide = Validate::rule([
  107. 'skuCode|商品编号'=>'require|max:255',
  108. 'exam_status|审核状态'=>'require|number|in:0,1,2,3,4,5,6,7',
  109. 'offline_reason|线下原因'=>'requireIf:exam_status,5|max:255',
  110. 'offline_remark|下线备注'=>'requireIf:exam_status,5|max:255',
  111. 'plat_code|平台商品编码'=>'requireIf:exam_status,3|max:255',
  112. 'exam_remark|审核备注'=>'max:255',
  113. 'good_ladder|售价阶梯'=>'requireIf:exam_status,6|array',
  114. 'proof_type|售价凭证类型'=>'requireIf:exam_status,6|number|gt:0',
  115. 'proof_url|售价凭证'=>'requireIf:exam_status,6|max:255',
  116. ]);
  117. if($valide->check($post)==false) $this->error($valide->getError());
  118. $goodPlat = new GoodPlatform();
  119. $goodNake = new GoodNake();
  120. $platform = $goodPlat->where(['skuCode'=>$post['skuCode'],'is_del'=>0])->findOrEmpty();
  121. if($platform->isEmpty()) $this->error('未找到商品数据');
  122. if($platform->is_fixed==1){
  123. //使用实时金价
  124. $nake=$goodNake->where(['spuCode'=> $platform->spuCode,'is_del'=>0,'nake_fee'=>0])
  125. ->findOrEmpty();
  126. if($nake->isEmpty()==false) $this->error('一口价商品请先完善商品成本单价');
  127. }
  128. if($post['exam_status']==3){
  129. $is_exit = $goodPlat
  130. ->where(['plat_code' =>$post['plat_code'],'is_del' =>0, 'exam_status' =>3])//bbc商品编号唯一不可重复
  131. ->where('id', '<>', $platform['id'])
  132. ->findOrEmpty();
  133. if($is_exit->isEmpty()) $platform->plat_code=$post['plat_code'];
  134. else $this->error("平台商品编码 {$post['plat_code']} 已存在");
  135. }
  136. if($post['exam_status']==5){
  137. $platform->is_compliance=0;
  138. $platform->compliance_remark='';
  139. }
  140. $before= $platform['exam_status'];
  141. $platform->exam_status=$post['exam_status'];
  142. $platform->updatetime=date('Y-m-d H:i:s');
  143. $createrid= $this->uid;
  144. $creater= $this->uname;
  145. $platform->startTrans();
  146. try {
  147. $up = $platform->save();
  148. if($up){
  149. $data=[
  150. 'code'=>$platform->skuCode,
  151. 'exam_status'=>$post['exam_status'],//$exam_status,
  152. 'type'=>2,
  153. 'exam_id'=>$createrid,
  154. 'exam_name'=>$creater,
  155. 'exam_remark'=>$post['exam_remark'],
  156. 'addtime'=>date('Y-m-d H:i:s')
  157. ];
  158. $inr=(new GoodExam())->save($data);
  159. if($inr){
  160. if ($post['exam_status'] == 6) {
  161. //todo::需要去掉;
  162. if($post['proof_url']!=''){
  163. $proof=[
  164. 'spuCode'=>$platform->spuCode,
  165. 'proof_type'=>$post['proof_type'],
  166. 'proof_url'=>$post['proof_url'],
  167. 'is_del'=>0,
  168. 'creater'=>$this->uname,
  169. 'createrid'=>$this->uid,
  170. 'addtime'=>date('Y-m-d H:i:s'),
  171. 'updatetime'=>date('Y-m-d H:i:s')
  172. ];
  173. GoodProof::create($proof);
  174. }
  175. if(empty($post['good_ladder']))throw new Exception('商品阶梯价不能为空');
  176. $goodLadder =new GoodLadder();
  177. $saveArr=[];
  178. foreach ($post['good_ladder'] as $value){
  179. $lemp=[];
  180. isset($value['id'])?$lemp['id']=$value['id']:$lemp['addtime'] = date('Y-m-d H:i:s');
  181. $lemp['skuCode']=$platform->spuCode;
  182. $lemp['min_num'] = $value['min_num'];
  183. $lemp['max_num'] = 0;
  184. $lemp['sale_price'] = $value['sale_price'];
  185. $lemp['market_price'] = $value['market_price'];
  186. $lemp['market_platform'] = $value['market_platform'];
  187. $lemp['cost_fee'] = $value['cost_fee'];
  188. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  189. $lemp['updatetime'] =date('Y-m-d H:i:s');
  190. $saveArr[]=$lemp;
  191. }
  192. $ladderUp = $goodLadder->saveAll($saveArr);
  193. if($ladderUp==false) throw new Exception('商品阶梯价录入失败');
  194. }
  195. }else throw new Exception('商品审核失败');
  196. }else throw new Exception('商品审核失败');
  197. $platform->commit();
  198. //流程记录
  199. $event=[ 'order_type' => 'BBCSX',
  200. 'order_code' =>$platform->skuCode,//咨询单详情编号
  201. 'order_id' => $platform->id,
  202. 'order_status' => 2,
  203. 'action_process' =>$post['exam_status'],
  204. 'action_status' => $before,
  205. 'action_uid' => $this->uid,
  206. 'action_name' => $this->uname,
  207. ];
  208. event('ProcessOrder',$event);
  209. if($post['exam_status']==5){
  210. //下线记录
  211. $enevt=[
  212. 'spuCode' => $platform->spuCode,
  213. 'skuCodes' => $platform->skuCode,
  214. 'type' => 2,
  215. 'good_name' => (new GoodBasic())->where('spuCode',$platform->spuCode)->value('good_name', ''),
  216. 'offline_reason' => $post['offline_reason'],
  217. 'offline_remark' => $post['offline_remark'],
  218. 'createrid' => $createrid,
  219. 'creater' => $creater,
  220. ];
  221. event('GoodOff',$enevt);
  222. }
  223. $this->success('商品审核成功');
  224. }catch (Exception $e){
  225. $platform->rollback();
  226. $this->error($e->getMessage().$e->getLine().$e->getFile());
  227. }
  228. }
  229. }