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