Orderback.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\GoodLog;
  6. use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
  7. use think\App;
  8. use think\Exception;
  9. use think\facade\Db;
  10. use think\facade\Validate;
  11. //退货单
  12. class Orderback extends Base
  13. {
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. }
  18. public function list()
  19. {
  20. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  21. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  22. $where = [['a.is_del', "=", 0]];
  23. $thNo = isset($this->post['thNo']) && $this->post['thNo'] != "" ? trim($this->post['thNo']) : "";
  24. if ($thNo != "") {
  25. $where[] = ['a.thNo', "like", "%{$thNo}%"];
  26. }
  27. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  28. if ($status !== "") {
  29. // $where['status'] = $status;
  30. $where[] = ['a.status', "=", $status];
  31. }
  32. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  33. if ($post_code != "") {
  34. $where[] = ['a.post_code', "like", "%{$post_code}%"];
  35. }
  36. $post_compay = isset($this->post['post_compay']) && $this->post['post_compay'] != "" ? trim($this->post['post_compay']) : "";
  37. if ($post_compay != "") {
  38. $where[] = ['a.post_company', "=", $post_compay];
  39. }
  40. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] != "" ? trim($this->post['customer_code']) : "";
  41. if ($customer_code != "") {
  42. $where[] = ['a.customer_code', "like", "%{$customer_code}%"];
  43. }
  44. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] != "" ? trim($this->post['relaComNo']) : "";
  45. if ($relaComNo != "") $where[] = ['b.supplierNo', '=', $relaComNo];
  46. $order_code = isset($this->post['order_code']) && $this->post['order_code'] != "" ? trim($this->post['order_code']) : "";
  47. if ($order_code != "") {
  48. $where[] = ['a.orderCode', "like", "%{$order_code}%"];
  49. }
  50. $out_code = isset($this->post['out_code']) && $this->post['out_code'] != "" ? trim($this->post['out_code']) : "";
  51. if ($out_code != "") {
  52. $where[] = ['a.outCode', "like", "%{$out_code}%"];
  53. }
  54. $return_code = isset($this->post['return_code']) && $this->post['return_code'] != "" ? trim($this->post['return_code']) : "";
  55. if ($return_code != "") {
  56. $where[] = ['a.returnCode', "like", "%{$return_code}%"];
  57. }
  58. $start = isset($this->post['start']) && $this->post['start'] != '' ? $this->post['start'] : "";
  59. if ($start !== "") {
  60. $where[] = ['a.addtime', ">=", $start];
  61. }
  62. $end = isset($this->post['end']) && $this->post['end'] != '' ? $this->post['end'] : "";
  63. if ($end !== "") {
  64. $where[] = ['a.addtime', "<=", $end];
  65. }
  66. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  67. if ($order_source !== "") {
  68. $where[] = ['b.order_source', "=", $order_source];
  69. }
  70. $supplierNo = trim($this->post['supplierNo'] ?? '');
  71. if ($supplierNo !== '') $where[] = ['a.supplierNo', 'like', '%'.$supplierNo.'%'];
  72. $companyNo = trim($this->post['companyNo'] ?? '');
  73. if ($companyNo !== '') $where[] = ['a.companyNo', 'like', '%'.$companyNo.'%'];
  74. $condition = [];
  75. // $role=$this->checkRole();
  76. // if(!empty($role['write']) && $this->uid!=""){
  77. // // $where[]=["a.apply_id","in",$role['write']];
  78. // $condition .="cgderid = {$this->uid} or apply_id in (".implode(',',$role['write']).")";
  79. // }
  80. // $hand = resign_hand_user($this->uid);
  81. // $role = $this->checkDataShare();
  82. // if (!empty($role[DataGroupModel::$type_全部])) $condition .= "cgderid in {$hand} or apply_id in (" . implode(',',
  83. // $role[DataGroupModel::$type_全部]) . ")";
  84. //只有level2的账号过滤数据权限
  85. if ($this->level == 2) {
  86. $role = $this->checkDataShare();
  87. $hand = resign_hand_user($this->uid, 0);
  88. if (!empty($role[DataGroupModel::$type_全部])) {
  89. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  90. $condition[] = ['a.apply_id', 'in', $arr];
  91. $condition[] = ['a.cgderid', 'in', $hand];
  92. $supplierNos = Db::connect('mysql_sys')
  93. ->name('supplier')
  94. ->where(['is_del' => 0, 'personid' => $arr])
  95. ->column('code');
  96. $where[] = ['a.supplierNo', 'in', $supplierNos];
  97. }
  98. }
  99. //供应商账号不允许看到库存品数据
  100. if ($this->level == 3) $where[] = ['b.is_stock', '<>', 1];
  101. // if(!empty($role['platform']) ){
  102. // $where[]=["platform_id","in",$role['platform']];
  103. // }
  104. $count = Db::name("order_back")
  105. ->alias('a')
  106. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  107. ->where($where)
  108. ->where(function ($query) use ($condition) {
  109. $query->whereOr($condition);
  110. })
  111. ->count('a.id');
  112. $total = ceil($count / $size);
  113. $page = $page >= $total ? $total : $page;
  114. $list = Db::name("order_back")
  115. ->alias('a')
  116. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  117. ->where($where)
  118. ->where(function ($query) use ($condition) {
  119. $query->whereOr($condition);
  120. })
  121. ->field('a.*,b.order_source')
  122. ->page($page, $size)
  123. ->order("a.addtime desc")
  124. ->select()
  125. ->toArray();
  126. $data = [];
  127. $all_wsm = Db::name("warehouse_info")
  128. ->alias("a")
  129. ->where(["a.wsm_code" => array_column($list, 'return_wsm')])
  130. ->column("a.name,a.supplierNo", 'a.wsm_code');//b.name,b.code
  131. $userCommon = \app\admin\common\User::getIns();
  132. $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_column($all_wsm, 'supplierNo'))]);
  133. foreach ($list as $value) {
  134. $value['wsm_name'] = "";
  135. $value['wsm_supplier'] = '';
  136. $value['wsm_supplierNo'] = '';
  137. if ($value['return_wsm'] != "") {
  138. // $wsmcode = Db::name("warehouse_info")
  139. // ->alias("a")
  140. //// ->leftJoin("supplier b","a.supplierNo=b.code")
  141. // ->where(["a.wsm_code"=>$value['return_wsm']])
  142. // ->field("a.name as wsm_name,a.supplierNo")//b.name,b.code
  143. // ->find();
  144. $value['wsm_name'] = $all_wsm[$value['return_wsm']]['name'] ?? '';//isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  145. $value['wsm_supplier'] = $names['data'][$all_wsm[$value['return_wsm']]['supplierNo']] ?? '';//isset($wsmcode['name']) ? $wsmcode['name']:"";
  146. $value['wsm_supplierNo'] = $all_wsm[$value['return_wsm']]['supplierNo'];//isset($wsmcode['code']) ? $wsmcode['code']:"";
  147. }
  148. // $value['customer_name'] = '';
  149. // if ($value['customer_code'] != '') {
  150. // $customer = Db::name("customer_info")->where(['companyNo'=>$value['customer_code']])->find();
  151. // $value['customer_name'] = $names['data'][$value['customer_code']] ?? '';//isset($customer['companyName'])?$customer['companyName']:'';
  152. // }
  153. $inorder = Db::name("order_backinfo")
  154. ->where(['thNo' => $value['thNo'], "is_del" => 0])
  155. ->select()
  156. ->toArray();
  157. $value['child'] = empty($inorder) ? [] : $inorder;
  158. // $value['supplierName'] = $names['data'][$value['supplierNo']] ?? '';//isset($customer['companyName'])?$customer['companyName']:'';
  159. //是否具有编辑权限
  160. // $value['is_allow_update'] = 0;
  161. // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  162. $data[] = $value;
  163. }
  164. return app_show(0, "获取成功", ["list" => $data, "count" => $count]);
  165. }
  166. /**
  167. * @return \think\response\Json|void
  168. * @throws \think\db\exception\DataNotFoundException
  169. * @throws \think\db\exception\DbException
  170. * @throws \think\db\exception\ModelNotFoundException
  171. */
  172. public function info(){
  173. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  174. if($thNo==""){
  175. return error_show(1004,"参数thNo不能为空");
  176. }
  177. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  178. if(empty($info)){
  179. return error_show(1004,"未找到数据");
  180. }
  181. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  182. $info['origin_price']=$orderinfo['origin_price'];
  183. $info['sale_price']=$orderinfo['sale_price'];
  184. $info['order_type']=$orderinfo['order_type'];
  185. $info['order_source']=$orderinfo['order_source'];
  186. $info['total_price']=$orderinfo['total_price'];
  187. // $info['companyNo']=$orderinfo['supplierNo'];
  188. // $info['company'] = Db::name('business')
  189. // ->where(['companyNo' => $orderinfo['supplierNo'], 'is_del' => 0])
  190. // ->value('company','');
  191. $info['addr_cn']=GetAddr($info['addr_code']);
  192. if($orderinfo['order_type']==3 || $orderinfo['order_type']==4){
  193. $goon = Db::name("good_zixun")
  194. ->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])
  195. ->find();
  196. $is_stock=0;
  197. }else {
  198. $goon = Db::name('good_platform')
  199. ->alias('a')
  200. ->leftJoin('good b', 'b.spuCode=a.spuCode')
  201. ->where(['a.skuCode' => $orderinfo['skuCode']])
  202. ->find();
  203. $is_stock=$goon['is_stock'];
  204. }
  205. if (empty($goon)) {
  206. return error_show(1003, "未找到商品数据");
  207. }
  208. $info['out_wsm_name']="";
  209. $info['out_wsm_supplier']='';
  210. $info['out_wsm_supplierNo']='';
  211. if($is_stock==1){
  212. $out =Db::name("order_out")->where(['outCode'=>$info['outCode']])->find();
  213. if($out==false){
  214. return error_show(1003, "未找到出库单数据");
  215. }
  216. if($out['wsm_code']!=''){
  217. // $wsmcode = Db::name("warehouse_info")
  218. // ->alias("a")
  219. //// ->leftJoin("supplier b","a.supplierNo=b.code")
  220. // ->where(["a.wsm_code"=>$out['wsm_code']])
  221. // ->field("a.name as wsm_name")
  222. // ->find();
  223. // $info['out_wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  224. // $info['out_wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  225. // $info['out_wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  226. }
  227. }
  228. $retutninfo = Db::name("order_return")->where(['returnCode'=>$info['returnCode']])->find();
  229. $info['apply_id'] = $retutninfo['apply_id'];
  230. $info['apply_name'] = $retutninfo['apply_name'];
  231. $info['return_tag'] = $retutninfo['return_tag'];
  232. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  233. $info['wsm_name']="";
  234. $info['wsm_supplier']='';
  235. $info['wsm_supplierNo']='';
  236. // if($info['return_wsm']!=""){
  237. // $wsmcode = Db::name("warehouse_info")
  238. // ->alias("a")
  239. //// ->leftJoin("supplier b","a.supplierNo=b.code")
  240. // ->where(["a.wsm_code"=>$info['return_wsm']])
  241. // ->field("a.name as wsm_name")
  242. // ->find();
  243. // $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  244. // $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  245. // $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  246. // }
  247. $inorder= Db::name("order_backinfo")
  248. ->alias("a")
  249. ->leftJoin("result_info b","a.error_code=b.result_code")
  250. ->where(['a.thNo'=>$info['thNo'],"a.is_del"=>0])
  251. ->field("a.*,b.result as error_msg")
  252. ->select()
  253. ->toArray();
  254. $info['child']=empty($inorder)? [] : $inorder;
  255. $info['can']=$int;
  256. //补充仓库名称
  257. $warehouse = Db::name('warehouse_info')
  258. ->alias('wi')
  259. ->where(['wi.is_del' => 0, 'wi.status' => 1])
  260. ->whereIn('wi.wsm_code', [$info['can_sell_wsm'], $info['defective_wsm'], $out['wsm_code']??'', $info['return_wsm']])
  261. // ->leftJoin('supplier s', 's.code=wi.supplierNo AND s.is_del=0')
  262. ->column('wi.name,wi.supplierNo', 'wi.wsm_code');
  263. $userCommon = \app\admin\common\User::getIns();
  264. $names = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_merge(array_column($warehouse, 'supplierNo')))]);
  265. // $info['company'] = $names['data'][$orderinfo['supplierNo']] ?? '';
  266. $info['can_sell_wsm_name'] = isset($warehouse[$info['can_sell_wsm']]['name']) ? $warehouse[$info['can_sell_wsm']]['name'] : '';
  267. $info['can_sell_wsm_supplierNo'] = isset($warehouse[$info['can_sell_wsm']]['supplierNo']) ? $warehouse[$info['can_sell_wsm']]['supplierNo'] : '';
  268. $info['can_sell_wsm_supplier'] = isset($warehouse[$info['can_sell_wsm']]['supplierNo']) ? $names['data'][$warehouse[$info['can_sell_wsm']]['supplierNo']]??'' : '';
  269. $info['defective_wsm_name'] = isset($warehouse[$info['defective_wsm']]['name']) ? $warehouse[$info['defective_wsm']]['name'] : '';
  270. $info['defective_wsm_supplierNo'] = isset($warehouse[$info['defective_wsm']]['supplierNo']) ? $warehouse[$info['defective_wsm']]['supplierNo'] : '';
  271. $info['defective_wsm_supplier'] = isset($warehouse[$info['defective_wsm']]['supplierNo'])?$names['data'][$warehouse[$info['defective_wsm']]['supplierNo']]??'' : '';
  272. if (isset($out) && $out['wsm_code'] != '') {
  273. $info['out_wsm_name'] = $warehouse[$info['out_wsm_name']]['name'] ?? '';
  274. $info['out_wsm_supplier'] = $names['data'][$warehouse[$info['out_wsm_name']]['supplierNo']] ?? '';
  275. $info['out_wsm_supplierNo'] = $warehouse[$info['out_wsm_name']]['supplierNo'] ?? '';
  276. }
  277. if ($info['return_wsm'] != '') {
  278. $info['wsm_name'] = $warehouse[$info['wsm_name']]['name'] ?? '';
  279. $info['wsm_supplier'] = $names['data'][$warehouse[$info['wsm_name']]['supplierNo']] ?? '';
  280. $info['wsm_supplierNo'] = $warehouse[$info['wsm_name']]['supplierNo'] ?? '';
  281. }
  282. return app_show(0, "获取成功", $info);
  283. }
  284. /**
  285. * @return \think\response\Json|void
  286. * @throws \think\db\exception\DataNotFoundException
  287. * @throws \think\db\exception\DbException
  288. * @throws \think\db\exception\ModelNotFoundException
  289. */
  290. public function check(){
  291. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  292. if($thNo==""){
  293. return error_show(1004,"参数thNo不能为空");
  294. }
  295. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  296. if(empty($info)){
  297. return error_show(1004,"未找到数据");
  298. }
  299. $normal = isset($this->post['normal']) && $this->post['normal']!=="" ? intval($this->post['normal']):"";
  300. if($normal===""){
  301. return error_show(1004,"参数normal不能为空");
  302. }
  303. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  304. if($info['status']== 2){
  305. return error_show(1002,"退货单已验货");
  306. }
  307. $receive=$normal+array_sum(array_column($errorlist,'error_num'));
  308. $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
  309. $info['received_num'] = $receive;
  310. $info['normal_num'] = $normal;
  311. $info['remark'] = $remark;
  312. $str = $info['status'];
  313. $info['status'] =empty($errorlist)?3: 2;
  314. $info['updatetime'] = date("Y-m-d H:i:s");
  315. Db::startTrans();
  316. try{
  317. $up=Db::name("order_back")->save($info);
  318. if($up){
  319. $stn = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  320. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$stn,"CKTHD",$info['status'],$info);
  321. if($info['status'] == 2) $roleid = [10, 31, 41];//特殊处理,写入到10采购负责人、31库管人员、41库管-张凯旋这三个角色下的所有人
  322. else $roleid = [31,41];//特殊处理,写入到31库管人员、41库管-张凯旋这三个角色下的所有人
  323. $handle_user_list = Db::name('user_role')
  324. ->where('is_del', 0)
  325. ->whereIn('roleid', $roleid)
  326. ->column('uid');
  327. $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => $info['status'], 'order_type' => "CKTHD", "before_status" => $str, 'handle_user_list' => implode(',', $handle_user_list)];
  328. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  329. if(empty($errorlist)){
  330. Db::commit();
  331. return app_show(0,'更新成功');
  332. }
  333. foreach($errorlist as $value){
  334. $data=[];
  335. isset($value['id'])&&$value['id']!=''?$data['id']=$value['id']:"";
  336. $data['thNo']=$thNo;
  337. $data['error_num']=$value['error_num'];
  338. $data['error_code']=$value['error_code'];
  339. $data['error_remark']=$value['error_remark'];
  340. $data['is_del']=isset($value['is_del'])?$value['is_del']:0;
  341. isset($value['id'])&&$value['id']!=''? "" : $data['addtime']=date("Y-m-d H:i:s");
  342. $data['updatetime']=date("Y-m-d H:i:s");
  343. $in = Db::name("order_backinfo")->save($data);
  344. if(!$in){
  345. Db::rollback();
  346. return error_show(1005,'更新失败');
  347. }
  348. }
  349. Db::commit();
  350. return app_show(0,'更新成功');
  351. }
  352. Db::rollback();
  353. return error_show(1005,'更新失败');
  354. }catch (\Exception $e){
  355. Db::rollback();
  356. return error_show(1004,$e->getMessage());
  357. }
  358. }
  359. public function CheckExam(){
  360. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  361. if($thNo==""){
  362. return error_show(1004,"参数thNo不能为空");
  363. }
  364. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  365. if(empty($info)){
  366. return error_show(1004,"未找到数据");
  367. }
  368. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  369. Db::startTrans();
  370. try{
  371. $temp=$info['status'];
  372. $info['status'] =3;
  373. $info['updatetime'] = date("Y-m-d H:i:s");
  374. $up=Db::name("order_back")->save($info);
  375. if($up){
  376. $stn = ["order_code"=>$thNo,"status"=>$temp,"action_remark"=>'',"action_type"=>"edit"];
  377. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "CKTHD", $info['status'], $stn);
  378. //特殊处理,写入到31库管人员、41库管-张凯旋这三个角色下的所有人
  379. $handle_user_list = Db::name('user_role')
  380. ->where('is_del', 0)
  381. ->whereIn('roleid', [31, 41])
  382. ->column('uid');
  383. $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => 3, "order_type" => "CKTHD", "before_status" => $temp, 'handle_user_list' => implode(',', $handle_user_list)];
  384. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  385. if(empty($errorlist)){
  386. $up =Db::name("order_backinfo")->where(["thNo"=>$thNo,"is_del"=>0])->save(["status"=>1,
  387. "updatetime"=>date("Y-m-d H:i:s")]);
  388. if($up){
  389. Db::commit();
  390. return app_show(0,'更新成功');
  391. }else{
  392. Db::rollback();
  393. return error_show(1005,'异常记录数据更新失败');
  394. }
  395. }else{
  396. foreach($errorlist as $value){
  397. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  398. if(empty($temp)){
  399. Db::rollback();
  400. return error_show(1005,'异常记录数据未找到');
  401. }
  402. $temp['status']=$value['status'];
  403. $temp['exam_remark']=$value['remark'];
  404. $temp['updatetime']=date("Y-m-d H:i:s");
  405. $com = Db::name("order_backinfo")->save($temp);
  406. if($com==false){
  407. Db::rollback();
  408. return error_show(1005,'异常记录数据更新失败');
  409. }
  410. }
  411. Db::commit();
  412. return app_show(0,'更新成功');
  413. }
  414. }
  415. Db::rollback();
  416. return error_show(1005,'更新失败');
  417. }catch (\Exception $e){
  418. Db::rollback();
  419. return error_show(1004,$e->getMessage());
  420. }
  421. }
  422. public function Exam(){
  423. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  424. if($thNo==""){
  425. return error_show(1004,"参数thNo不能为空");
  426. }
  427. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  428. if(empty($info)){
  429. return error_show(1004,"未找到数据");
  430. }
  431. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  432. if($status===""){
  433. return error_show(1004,"参数status不能为空");
  434. }
  435. $return_wsm=isset($this->post["return_wsm"])&&$this->post["return_wsm"]!=""?trim($this->post["return_wsm"]):"";
  436. $normal_num=isset($this->post["normal_num"])&&$this->post["normal_num"]!=""?intval($this->post["normal_num"])
  437. :"";
  438. // $defective_wsm=isset($this->post["defective_wsm"])&&$this->post["defective_wsm"]!=""?trim($this->post["defective_wsm"]):"";
  439. // $defective_num=isset($this->post["defective_num"])&&$this->post["defective_num"]!==""?intval($this->post["defective_num"]):"";
  440. // $loss_num=isset($this->post["loss_num"])&&$this->post["loss_num"]!=""?intval($this->post["loss_num"]):"";
  441. if($status==4){
  442. // if($defective_num===""){
  443. // return error_show(1004,"参数defective_num不能为空");
  444. // }
  445. // if($loss_num===""){
  446. // return error_show(1004,"参数loss_num不能为空");
  447. // }
  448. if($normal_num===""){
  449. return error_show(1004,"参数normal_num不能为空");
  450. }
  451. // if($defective_wsm===""){
  452. // return error_show(1004,"参数defective_wsm不能为空");
  453. // }
  454. if($return_wsm===""){
  455. return error_show(1004,"参数return_wsm不能为空");
  456. }
  457. $info['return_wsm']=$return_wsm;
  458. $info['normal_num']=$normal_num;
  459. // $info['loss_num']=$loss_num;//order_back表里没有这三个字段,不知道是干嘛的
  460. // $info['defective_wsm']=$defective_wsm;
  461. // $info['defective_num']=$defective_num;
  462. }
  463. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  464. Db::startTrans();
  465. try{
  466. $var = $info['status'];
  467. $info['status'] =$status;
  468. $info['remark'] =$remark;
  469. $info['updatetime'] = date("Y-m-d H:i:s");
  470. $up=Db::name("order_back")->save($info);
  471. if($up){
  472. $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  473. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"CKTHD",$info['status'],$this->post);
  474. if (in_array($status, [2, 3])) {
  475. if ($status == 2) $roleid = [10, 31, 41];//特殊处理,写入到10采购负责人、31库管人员、41库管-张凯旋这三个角色下的所有人
  476. else $roleid = [31, 41];//特殊处理,写入到、31库管人员、41库管-张凯旋这三个角色下的所有人
  477. $handle_user_list = Db::name('user_role')
  478. ->where('is_del', 0)
  479. ->whereIn('roleid', $roleid)
  480. ->column('uid');
  481. $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => $status, "order_type" => "CKTHD", "before_status" => $var, 'handle_user_list' => implode(',', $handle_user_list)];
  482. } else $process = ["order_code" => $info['thNo'], "order_id" => $info['id'], "order_status" => $status, "order_type" => "CKTHD", "before_status" => $var];
  483. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  484. Db::commit();
  485. return app_show(0,'更新成功');
  486. }
  487. Db::rollback();
  488. return error_show(1005,'更新失败');
  489. }catch (\Exception $e){
  490. Db::rollback();
  491. return error_show(1004,$e->getMessage());
  492. }
  493. }
  494. //新写一个退货接口
  495. public function ExamNew()
  496. {
  497. $param = $this->request->only(['thNo', 'status', 'status_remark', 'can_sell_wsm' => '', 'can_sell_num' => 0, 'defective_wsm' => '', 'defective_num' => 0, 'loss_num' => 0], 'post', 'trim');
  498. $val = Validate::rule(['thNo|退货编码' => 'require', 'status|状态' => 'require|number|in:4,2,1', 'status_remark|备注' => 'checkRemark:']);
  499. $val->extend('checkRemark', function ($val, $rule, $data) {
  500. return $data['status'] == 4 ? true : (empty($val) ? '请填写备注' : true);
  501. });
  502. if (!$val->check($param)) return error_show(1004, $val->getError());
  503. Db::startTrans();
  504. try {
  505. $info = Db::name("order_back")
  506. ->field('id,order_type,status,outCode,good_code,return_num,orderCode,returnCode,apply_id,apply_name')
  507. ->where(['thNo' => $param['thNo'], 'is_del' => 0])
  508. ->find();
  509. if (empty($info)) throw new Exception('未找到数据');
  510. $sale= Db::name('sale')->where(['orderCode'=>$info['orderCode'],"is_del"=>0])->find();
  511. if($sale==false){
  512. Db::rollback();
  513. return error_show(1004,"未找到销售单数据");
  514. }
  515. $spuCode= $info['good_code'];
  516. if($sale['order_type']!=1){
  517. if($sale['order_type']==3 ||$sale['order_type']==4){
  518. $goon = Db::name("good_zixun")->where(["spuCode"=>$sale['good_code'],"is_del"=>0])->find();
  519. $isZx=1;
  520. }else {
  521. $goon = Db::name('good_basic')->where(['spuCode' => $sale['good_code']])->find();
  522. $isZx=2;
  523. }
  524. $spuCode = $this->CheckGoodZx($goon,$isZx,$param['thNo']);
  525. }
  526. $out =Db::name("order_out")->where(['outCode'=>$info['outCode']])->find();
  527. if($out==false){
  528. Db::rollback();
  529. return error_show(1004,"未找到发货单数据");
  530. }
  531. $returninfo =Db::name("order_return")->where(['returnCode'=>$info['returnCode']])->find();
  532. if($returninfo==false){
  533. Db::rollback();
  534. return error_show(1004,"未找到售后单数据");
  535. }
  536. $sabebn =Db::name("sale_info")->where([["orderCode",'=',$info['orderCode']],["num",">",0]])->select()->toArray();
  537. if($param['can_sell_num']!=0&& $param['can_sell_wsm']!=''){
  538. // if($sale['is_stock']==1){ //库存品退回原仓库 备库单释放数量 采购单
  539. // $param['can_sell_wsm'] = $out['wsm_code'];
  540. // }
  541. $stock = Db::name("good_stock")->where(["spuCode"=>$spuCode,'wsm_code'=>$param['can_sell_wsm']])
  542. ->find();
  543. if(empty($stock)) {
  544. $stock=[
  545. "spuCode"=>$spuCode,
  546. "wsm_code"=>$param['can_sell_wsm'],
  547. "usable_stock"=>0,
  548. "wait_out_stock"=>0,
  549. "wait_in_stock"=>0,
  550. "total_stock"=>0,
  551. "addtime"=>date("Y-m-d H:i:s"),
  552. "updatetime"=>date("Y-m-d H:i:s"),
  553. ];
  554. }
  555. $stock['usable_stock']+=$param['can_sell_num'];
  556. $stock['updatetime']=date("Y-m-d H:i:s");
  557. $st_up = Db::name("good_stock")->save($stock);
  558. if($st_up==false){
  559. return error_show(1005,'可售商品入库失败');
  560. }
  561. $stockid = isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID();
  562. if(!empty($sabebn)){
  563. $total_num =$param['can_sell_num'];
  564. foreach ($sabebn as $ve){
  565. $tempnum=0;
  566. if ($total_num==0) break;
  567. if($total_num>=$ve['num']){
  568. $tempnum = $ve['num'];
  569. $total_num-=$ve['num'];
  570. $ve['th_num']+=$ve['num'];
  571. $ve['num']=0;
  572. }else{
  573. $tempnum = $total_num;
  574. $ve['num']-=$total_num;
  575. $ve['th_num']+=$total_num;
  576. $total_num=0;
  577. }
  578. $bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
  579. if($bnin==false){
  580. Db::rollback();
  581. return error_show(1005, '可售商品Bn库存数入库失败');
  582. }
  583. $up=Db::name("sale_info")->save($ve);
  584. if($up==false){
  585. Db::rollback();
  586. return error_show(1005, '可售商品Bn库存数入库失败');
  587. }
  588. $bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
  589. if($bnin==false){
  590. Db::rollback();
  591. return error_show(1005, '可售商品Bn库存数入库失败');
  592. }
  593. }
  594. }else{
  595. if($sale['order_type']==1){
  596. $ordernum = Db::name("order_num")->where(['orderCode' =>$info['orderCode']])->find();
  597. if ($ordernum == false) {
  598. Db::rollback();
  599. return error_show(1005, '未找到关联采购单');
  600. }
  601. $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  602. if ($cgd == false) {
  603. Db::rollback();
  604. return error_show(1005, '未找到采购单数据');
  605. }
  606. $bn =makeNo("BN");
  607. $yp=GoodStockInfo::AddBn($stockid,$bn,$param['can_sell_num'],$cgd['good_price']);
  608. if($yp==false){
  609. Db::rollback();
  610. return error_show(1005, '商品批次退货入库失败');
  611. }
  612. }
  613. }
  614. $good_data=['good_log_code'=>$param['thNo'],"stock_id"=> $stockid,"type"=>1,'stock'=>$param['can_sell_num'],"stock_name"=>"usable_stock"];
  615. GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
  616. }
  617. if($param['defective_num']!=0&& $param['defective_wsm']!=''){
  618. $defective = Db::name("good_stock")->where(["spuCode"=>$spuCode,'wsm_code'=>$param['defective_wsm']])->find();
  619. if(empty($defective)) {
  620. $defective=[
  621. "spuCode"=>$spuCode,
  622. "wsm_code"=>$param['defective_wsm'],
  623. "usable_stock"=>0,
  624. "wait_out_stock"=>0,
  625. "wait_in_stock"=>0,
  626. "total_stock"=>0,
  627. "addtime"=>date("Y-m-d H:i:s"),
  628. "updatetime"=>date("Y-m-d H:i:s"),
  629. ];
  630. $order = ["order_code"=>$spuCode,"status"=>1,"action_remark"=>'', "action_type"=>"create"];
  631. }else{
  632. $order = ["order_code"=>$spuCode,"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
  633. }
  634. $defective['usable_stock']+=$param['defective_num'];
  635. $defective['updatetime'] = date("Y-m-d H:i:s");
  636. $upd= Db::name("good_stock")->save($defective);
  637. if($upd==false){
  638. Db::rollback();
  639. return error_show(1005,'次品商品入库失败');
  640. }
  641. $stockid = isset($defective['id']) ? $defective['id'] : Db::name("good_stock")->getLastInsID();
  642. $sabebn =Db::name("sale_info")->where(["orderCode"=>$info['orderCode']])->select()->toArray();
  643. if(!empty($sabebn)){
  644. $total_num =$param['defective_num'];
  645. foreach ($sabebn as $ve){
  646. $tempnum=0;
  647. if ($total_num==0) break;
  648. if($total_num>=$ve['num']){
  649. $tempnum = $ve['num'];
  650. $total_num-=$ve['num'];
  651. $ve['th_num']+=$ve['num'];
  652. $ve['num']=0;
  653. }else{
  654. $tempnum = $total_num;
  655. $ve['num']-=$total_num;
  656. $ve['th_num']+=$total_num;
  657. $total_num=0;
  658. }
  659. $bnin=GoodStockInfo::ReturnAdd($stockid,$ve['bnCode'],$tempnum,$ve['stockid']);
  660. if($bnin==false){
  661. Db::rollback();
  662. return error_show(1005, '可售商品Bn库存数入库失败');
  663. }
  664. $up=Db::name("sale_info")->save($ve);
  665. if($up==false){
  666. Db::rollback();
  667. return error_show(1005, '可售商品Bn库存数入库失败');
  668. }
  669. $bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
  670. if($bnin==false){
  671. Db::rollback();
  672. return error_show(1005, '可售商品Bn库存数入库失败');
  673. }
  674. }
  675. }else{
  676. if($sale['order_type']==1){
  677. $ordernum = Db::name("order_num")->where(['orderCode' =>$info['orderCode']])->find();
  678. if ($ordernum == false) {
  679. Db::rollback();
  680. return error_show(1005, '未找到关联采购单');
  681. }
  682. $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  683. if ($cgd == false) {
  684. Db::rollback();
  685. return error_show(1005, '未找到采购单数据');
  686. }
  687. $bn =makeNo("BN");
  688. $yp=GoodStockInfo::AddBn($stockid,$bn,$param['defective_num'],$cgd['good_price']);
  689. if($yp==false){
  690. Db::rollback();
  691. return error_show(1005, '商品批次退货入库失败');
  692. }
  693. }
  694. }
  695. $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>isset($defective['id'])? $defective['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$param['defective_num'],"stock_name"=>"usable_stock"];
  696. GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
  697. }
  698. $update_data = ['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')];
  699. //status==4通过,其他值表示驳回
  700. if ($param['status'] != 4) $update_data['status_remark'] = $param['status_remark'];
  701. else {
  702. $update_data['can_sell_wsm'] = $param['can_sell_wsm'];
  703. $update_data['can_sell_num'] = $param['can_sell_num'];
  704. $update_data['defective_wsm'] = $param['defective_wsm'];
  705. $update_data['defective_num'] = $param['defective_num'];
  706. $update_data['loss_num'] = $param['loss_num'];
  707. if($sale['is_stock']==1){
  708. $sale['th_num']+= $info['return_num'];
  709. if($sale['th_num']==$sale['send_num']&& $sale['wsend_num']==0){
  710. $sale['status']=3;
  711. }
  712. $sale['th_fee']+= round($info['return_num']*$sale['sale_price'],2);
  713. $sale['updatetime']= date("Y-m-d H:i:s");
  714. $uap=Db::name("sale")->save($sale);
  715. if($uap==false){
  716. Db::rollback();
  717. return error_show(1005,'销售单订单更新失败');
  718. }
  719. // $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
  720. // if($ordernum==false){
  721. // Db::rollback();
  722. // return error_show(1005,'未找到关联采购单');
  723. // }
  724. // $ordernum['send_num']-=$info['return_num'];
  725. // $orderup =Db::name("order_num")->save($ordernum);
  726. // if($orderup==false){
  727. // Db::rollback();
  728. // return error_show(1005,'关联数据更新失败');
  729. // }
  730. // $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
  731. // if($cgd==false){
  732. // Db::rollback();
  733. // return error_show(1005,'未找到采购单数据');
  734. // }
  735. // $cgd['th_fee']+= round($cgd['good_price']*$param['can_sell_num'],2);
  736. // $cgd['th_num']+= $param['can_sell_num'];
  737. // if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
  738. // $cgd['status']=4;
  739. // }
  740. // $cgd['updatetime']= date("Y-m-d H:i:s");
  741. // $cgdup =Db::name("purchease_order")->save($cgd);
  742. // if($cgdup==false){
  743. // Db::rollback();
  744. // return error_show(1005,'采购单数据更新失败');
  745. // }
  746. // if($cgd['bkcode']!=""){
  747. // $bk=Db::name("purchease_order")->where(["bkcode"=>$cgd['bkcode'],"order_type"=>1,"order_source"=>0,"is_del"=>0])->find();
  748. // if($bk==false){
  749. // Db::rollback();
  750. // return error_show(1005,'未找到备库单数据');
  751. // }
  752. // $orderbk = Db::name("order_bk")->where(['cgdNo'=>$bk['cgdNo'],"is_del"=>0])->find();
  753. // if($orderbk==false){
  754. // Db::rollback();
  755. // return error_show(1005,'备库单未完全入库');
  756. // }
  757. // $merge_num = Db::name("purchease_order")->where(["bkcode"=>$bk['bkcode'],"order_type"=>1,"is_del"=>0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")->find();
  758. //
  759. // $orderbk['balance_num']=$orderbk['total_num']-$merge_num['num'];
  760. // $orderbk['merge_num']=$merge_num['num'];
  761. // $orderbk['updatetime']=date("Y-m-d H:i:s");
  762. // $orderbkup=Db::name("order_bk")->save($orderbk);
  763. // if($orderbkup==false){
  764. // Db::rollback();
  765. // return error_show(1005,'备库单库存数据释放失败');
  766. // }
  767. // }
  768. }else{
  769. if($returninfo['return_tag']==1){
  770. $sale['th_num']+= $info['return_num'];
  771. if($sale['th_num']==$sale['send_num']&& $sale['wsend_num']==0){
  772. $sale['status']=3;
  773. }
  774. $sale['th_fee']+= round($info['return_num']*$sale['sale_price'],2);
  775. $sale['updatetime']= date("Y-m-d H:i:s");
  776. $uap=Db::name("sale")->save($sale);
  777. if($uap==false){
  778. Db::rollback();
  779. return error_show(1005,'销售单订单更新失败');
  780. }
  781. $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
  782. if($ordernum==false){
  783. Db::rollback();
  784. return error_show(1005,'未找到关联采购单');
  785. }
  786. $ordernum['send_num']-=$info['return_num'];
  787. $orderup =Db::name("order_num")->save($ordernum);
  788. if($orderup==false){
  789. Db::rollback();
  790. return error_show(1005,'关联数据更新失败');
  791. }
  792. $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
  793. if($cgd==false){
  794. Db::rollback();
  795. return error_show(1005,'未找到采购单数据');
  796. }
  797. $cgd['th_num']+= $info['return_num'];
  798. if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
  799. $cgd['status']=4;
  800. }
  801. $cgd['th_fee']+= round($info['return_num']*$cgd['good_price'],2);
  802. $cgd['updatetime']= date("Y-m-d H:i:s");
  803. $cgdup =Db::name("purchease_order")->save($cgd);
  804. if($cgdup==false){
  805. Db::rollback();
  806. return error_show(1005,'采购单数据更新失败');
  807. }
  808. }else{
  809. $sale['th_num']+= $info['return_num'];
  810. if($sale['th_num']==$sale['send_num']&& $sale['wsend_num']==0){
  811. $sale['status']=3;
  812. }
  813. $sale['th_fee']+= round($info['return_num']*$sale['sale_price'],2);
  814. $sale['updatetime']= date("Y-m-d H:i:s");
  815. $uap=Db::name("sale")->save($sale);
  816. if($uap==false){
  817. Db::rollback();
  818. return error_show(1005,'销售单订单更新失败');
  819. }
  820. // $ordernum =Db::name("order_num")->where(['orderCode'=>$info['orderCode']])->find();
  821. // if($ordernum==false){
  822. // Db::rollback();
  823. // return error_show(1005,'未找到关联采购单');
  824. // }
  825. // $ordernum['send_num']-=$info['return_num'];
  826. // $orderup =Db::name("order_num")->save($ordernum);
  827. // if($orderup==false){
  828. // Db::rollback();
  829. // return error_show(1005,'关联数据更新失败');
  830. // }
  831. // $cgd =Db::name("purchease_order")->where(["cgdNo"=>$ordernum['cgdNo'],"is_del"=>0])->find();
  832. // if($cgd==false){
  833. // Db::rollback();
  834. // return error_show(1005,'未找到采购单数据');
  835. // }
  836. // $cgd['th_fee']+= round($cgd['good_price']*$param['can_sell_num'],2);
  837. // $cgd['th_num']+= $param['can_sell_num'];
  838. // if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
  839. // $cgd['status']=4;
  840. // }
  841. // $cgd['updatetime']= date("Y-m-d H:i:s");
  842. // $cgdup =Db::name("purchease_order")->save($cgd);
  843. // if($cgdup==false){
  844. // Db::rollback();
  845. // return error_show(1005,'采购单数据更新失败');
  846. // }
  847. }
  848. }
  849. }
  850. $res = Db::name("order_back")
  851. ->where(['id' => $info['id']])
  852. ->update($update_data);
  853. if ($res) {
  854. $data=[
  855. "orderCode"=>$info['orderCode'],
  856. "th_type"=>3,
  857. "th_num"=>$info['return_num'],
  858. "th_fee"=>round($info['return_num']*$sale['sale_price'],2),
  859. "thCode"=>$info['returnCode'],
  860. "apply_id"=>$info['apply_id'],
  861. "apply_name"=>$info['apply_name'],
  862. "spuCode"=>$sale['good_code'],
  863. "good_name"=>$sale['good_name'],
  864. "cat_id"=>$sale['cat_id'],
  865. "addtime"=>date("Y-m-d H:i:s"),
  866. "status"=>1,
  867. "is_del"=>0
  868. ];
  869. $inse=Db::name("th_data")->insert($data);
  870. if($inse==false){
  871. Db::rollback();
  872. return error_show(1004,"退货单更新失败");
  873. }
  874. if($info['return_num']>=$out['send_num']){
  875. $out['status']=4;
  876. $out['updatetime']=date("Y-m-d H:i:s");
  877. $upout =Db::name("order_out")->save($out);
  878. if($upout==false){
  879. Db::rollback();
  880. return error_show(1005,'出库单数据更新失败');
  881. }
  882. }
  883. $stn = ["order_code" => $param['thNo'], "status" => $info['status'], "action_remark" => '', "action_type" => "edit"];
  884. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, "CKTHD", $param['status'], $stn);
  885. if (in_array($param['status'], [1,2, 3])) {
  886. if ($param['status'] == 2) $roleid = [10, 31, 41];//特殊处理,写入到10采购负责人、31库管人员、41库管-张凯旋这三个角色下的所有人
  887. else $roleid = [31, 41];//特殊处理,写入到、31库管人员、41库管-张凯旋这三个角色下的所有人
  888. $handle_user_list = Db::name('user_role')
  889. ->where('is_del', 0)
  890. ->whereIn('roleid', $roleid)
  891. ->column('uid');
  892. //如果是退货商品验收(节点1),把供应商负责人也加进去
  893. if ($param['status'] == 1) $handle_user_list[] = $sale['cgderid'];
  894. $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "CKTHD", "before_status" => $info['status'], 'handle_user_list' => implode(',', $handle_user_list)];
  895. } else $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "CKTHD", "before_status" => $info['status']];
  896. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  897. Db::commit();
  898. return app_show(0, '操作成功');
  899. } else throw new Exception('操作失败');
  900. } catch (Exception $exception) {
  901. Db::rollback();
  902. return error_show(1005, $exception->getMessage());
  903. }
  904. }
  905. }