Good.php 12 KB

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