Resign.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. <?php
  2. /**
  3. * 备库申请
  4. */
  5. namespace app\admin\controller;
  6. use app\admin\model\ActionLog;
  7. use app\admin\model\GoodLog;
  8. use app\admin\model\ProcessOrder;
  9. use think\facade\Cache;
  10. use think\facade\Config;
  11. use think\facade\Db;
  12. use think\App;
  13. //备货
  14. class Resign extends Base
  15. {
  16. public function __construct(App $app)
  17. {
  18. parent::__construct($app);
  19. }
  20. public function list(){
  21. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  22. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  23. $where =[['p.is_del',"=",0]];
  24. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  25. if($bkcode!=""){
  26. //$where['p.bk_code'] = $bk_code;
  27. $where[]=['p.bk_code',"like","%{$bkcode}%"];
  28. }
  29. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']):"";
  30. if($good_code!=""){
  31. // $where['p.good_code'] = $good_code;
  32. $where[]=['p.spuCode',"like","%{$good_code}%"];
  33. }
  34. $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code']!="" ? trim($this->post['good_type_code']):"";
  35. if($good_type_code!=""){
  36. // $where['p.good_type_code'] = $good_type_code;
  37. $where[]=['p.good_type_code',"like","%{$good_type_code}%"];
  38. }
  39. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  40. if($wsm_code!=""){
  41. //$where['p.wsm_code'] = $wsm_code;
  42. $where[]=['p.wsm_code',"=",$wsm_code];
  43. }
  44. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  45. if($good_name!=""){
  46. // $where['p.good_name'] = Db::raw(" like '%{$good_name}%'");
  47. $where[]=['p.good_name',"like","%{$good_name}%"];
  48. }
  49. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  50. if($apply_name!=""){
  51. // $where['p.apply_name'] =Db::Raw("like '%{$apply_name}%'");
  52. $where[]=['p.apply_name',"like","%{$apply_name}%"];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  55. if($status!==""){
  56. // $where['p.status'] = $status;
  57. $where[]=['p.status',"=",$status];
  58. }
  59. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  60. if($start!==""){
  61. //$where['p.addtime'] = Db::Raw(">= '{$start}'");
  62. $where[]=['p.addtime',">=",$start];
  63. }
  64. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  65. if($end!==""){
  66. // $where['p.addtime'] = Db::Raw("<= '{$end}'");
  67. $where[]=['p.addtime',"<=",$end];
  68. }
  69. $role=$this->checkRole();
  70. $condition='';
  71. if(!empty($role['write']) && $this->uid!=""){
  72. // $where[]=["a.apply_id","in",$role['write']];
  73. $condition .="p.cgderid = {$this->uid} or p.apply_id in (".implode(',',$role['write']).")";
  74. }
  75. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  76. if ($company_name !== "") $where[] = ["p.apply_id", 'in', get_company_item_user_by_name($company_name)];
  77. // if(!empty($role['platform']) ){
  78. // $where[]=["p.platform_id","in",$role['platform']];
  79. // }
  80. $count=Db::name("purchease")->alias('p')->leftJoin("depart_user u", "u.uid=p.apply_id AND u.is_del=0")->where($where)->where($condition)->count();
  81. $total = ceil($count/$size);
  82. $page = $page >= $total ? $total : $page;
  83. $list = Db::name("purchease")
  84. ->alias('p')
  85. ->field('p.*,u.itemid')
  86. ->leftJoin("depart_user u", "u.uid=p.apply_id AND u.is_del=0")
  87. ->where($where)
  88. ->where($condition)
  89. ->page($page,$size)
  90. ->order("p.addtime desc")
  91. ->cursor();
  92. $data=[];
  93. foreach ($list as $value){
  94. $value['wsm_name']="";
  95. $value['wsm_supplier']="";
  96. $value['wsm_supplierNo']="";
  97. if($value['wsm_code']!=""){
  98. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  99. ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  100. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  101. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  102. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  103. }
  104. $value['file_name'] ='';
  105. if($value['file_url']){
  106. $file= basename($value['file_url']);
  107. $value['file_name'] =substr($file,0,strripos($file,"_"));
  108. }
  109. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  110. $data[]=$value;
  111. }
  112. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  113. }
  114. public function add(){
  115. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  116. if($token==""){
  117. return error_show(101,'token不能为空');
  118. }
  119. $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  120. if($good_code==""){
  121. return error_show(1004,"参数good_code不能为空");
  122. }
  123. $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  124. if($good_num===""){
  125. return error_show(1004,"参数good_code不能为空");
  126. }
  127. $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  128. if($file_url===""){
  129. return error_show(1004,"参数file_url不能为空");
  130. }
  131. $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  132. if($mark==""){
  133. return error_show(1004,"参数remark不能为空");
  134. }
  135. $good =Db::name("good_basic")->where([["spuCode","=",$good_code],["is_del","=",0]])->find();
  136. if($good==false){
  137. return error_show(1004,"未找到商品数据");
  138. }
  139. $supplier=Db::name("supplier")->where("code","=",$good['supplierNo'])->find();
  140. if($supplier==false) return error_show(1004,"未找到供应商数据");
  141. // $bk= Db::name("purchease")->where([["spuCode","=",$good_code],["status","<>",2],["is_del","=",0]])->find();
  142. // if($bk!=false) return error_show(1004,"存在未完成备库单数据");
  143. // $cgd =Db::name("purchease_order")->where([["spuCode","=",$good_code],["status","in",[0,1]],["is_del","=",0]])->find();
  144. // if($cgd!=false) return error_show(1004,"存在未完成采购单数据");
  145. //查验仓库库存数量
  146. $stock =Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")->where
  147. (["spuCode"=>$good_code, "a.is_del"=>0,"a.status"=>1,"b.companyNo"=>$good['companyNo']])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
  148. // if(isset($stock['usable_stock'])&& $stock['usable_stock']!=0){
  149. // return error_show(1003,"库存数量为 {$stock['usable_stock']} 无法备库");
  150. // }
  151. //校验数量
  152. $goodnake = Db::name("good_nake")
  153. ->field('id,min_num')
  154. ->where([["spuCode", "=", $good_code], ["is_del", "=", 0]])
  155. ->order("min_num asc")
  156. ->find();
  157. if (empty($goodnake)) return error_show(1004, '未找到商品成本数据');
  158. $minnum = $goodnake['min_num'];
  159. if($good['is_stock']==1 && $good['stock_moq']>0){
  160. $minnum =$good['stock_moq'];
  161. }
  162. if ($minnum > $good_num) return error_show(1004, '该商品最低采购数量为' . $minnum);
  163. $lastime = isset($this->post['lastime'])&&$this->post['lastime']!="" ? $this->post['lastime']:"";
  164. if($lastime===""){
  165. return error_show(1004,"参数lastime不能为空");
  166. }
  167. // $data = GetUserInfo($token);
  168. // if((!empty($data) && $data['code']!=0) ||empty($data) ){
  169. // return error_show($data['code'],$data['message']);
  170. // }
  171. // $userinfo = $data['data'];
  172. $bk_code=makeNo("BK");
  173. $info = [
  174. "spuCode"=>$good['spuCode'],
  175. "good_name"=>$good['good_name'],
  176. "good_num"=>$good_num,
  177. "wsm_code"=>'',
  178. "companyNo"=>$good['companyNo'],
  179. "supplierNo"=>$good['supplierNo'],
  180. "file_url"=>$file_url,
  181. "lasttime"=>$lastime,
  182. "status"=>1,
  183. "remark"=>$mark,
  184. "cgder"=>$good['creater'],
  185. "cgderid"=>$good['createrid'],
  186. "addtime"=>date("Y-m-d H:i:s"),
  187. "updatetime"=>date("Y-m-d H:i:s"),
  188. "apply_id"=>$this->uid,
  189. "apply_name"=>$this->uname,
  190. "bk_code"=>$bk_code
  191. ];
  192. $in = Db::name("purchease")->insert($info,true);
  193. if($in>0){
  194. $order = ["order_type" => 'BHD', "order_code" => $bk_code, "order_id" => $in, "order_status" => 1, "before_status" => 1, 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
  195. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $order);
  196. $ste = ["order_code" => $bk_code, "status" => 0, "action_remark" => '', "action_type" => "create"];
  197. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $ste, "BHD", 1, $info);
  198. //台账记录
  199. Db::name('standing_book')
  200. ->insert([
  201. 'standBookNo' => makeNo("IO"),
  202. 'bk_code' => $bk_code,
  203. 'purchease_id' => $in,
  204. 'addtime' => date('Y-m-d H:i:s'),
  205. 'updatetime' => date('Y-m-d H:i:s')
  206. ]);
  207. return app_show(0,"新建成功",['bk_code'=>$bk_code]);
  208. }else{
  209. return error_show(1005,"新建失败");
  210. }
  211. }
  212. /**
  213. * @return \think\response\Json|void
  214. * @throws \think\db\exception\DataNotFoundException
  215. * @throws \think\db\exception\DbException
  216. * @throws \think\db\exception\ModelNotFoundException
  217. */
  218. public function copy(){
  219. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  220. if($id==""){
  221. return error_show(1001,'id不能为空');
  222. }
  223. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  224. if(empty($info)){
  225. return error_show(1002,'未找到数据');
  226. }
  227. // $data = GetUserInfo($this->post['token']);
  228. // if((!empty($data) && $data['code']!=0) ||empty($data) ){
  229. // return error_show($data['code'],$data['message']);
  230. // }
  231. //查验仓库库存数量
  232. // $stock =Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")->where
  233. // (["spuCode"=>$info['spuCode'], "a.is_del"=>0,"a.status"=>1,"b.companyNo"=>$info['companyNo']])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
  234. // if(isset($stock['usable_stock'])&& $stock['usable_stock']!=0){
  235. // return error_show(1003,"库存数量为 {$stock['usable_stock']} 无法备库");
  236. // }
  237. // $userinfo = $data['data'];
  238. $bk_code=makeNo("BK");
  239. $info['bk_code']=$bk_code;
  240. $info['status']=1;
  241. $info['addtime']=date("Y-m-d H:i:s");
  242. $info['updatetime']=date("Y-m-d H:i:s");
  243. $info['apply_id']=$this->uid;
  244. $info['apply_name']=$this->uname;
  245. unset($info['id']);
  246. $in = Db::name("purchease")->insert($info,true);
  247. if($in>0){
  248. $supplier = Db::name('supplier')
  249. ->field('id,person,personid')
  250. ->where('code', $info['supplierNo'])
  251. ->findOrEmpty();
  252. $order = ["order_type" => 'BHD', "order_code" => $bk_code, "order_id" => $in, "order_status" => 1, "before_status" => 1, 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
  253. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $order);
  254. $ste = ["order_code"=>$bk_code,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  255. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname],$ste,"BHD",1,$info);
  256. return app_show(0,"新建成功",['bk_code'=>$bk_code]);
  257. }else{
  258. return error_show(1005,"新建失败");
  259. }
  260. }
  261. /**
  262. * @return \think\response\Json|void
  263. * @throws \think\db\exception\DataNotFoundException
  264. * @throws \think\db\exception\DbException
  265. * @throws \think\db\exception\ModelNotFoundException
  266. */
  267. public function info(){
  268. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  269. if($id==""){
  270. return error_show(1001,'id不能为空');
  271. }
  272. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  273. if(empty($info)){
  274. return error_show(1002,'未找到数据');
  275. }
  276. $good =Db::name("good_basic")->where([["spuCode","=", $info['spuCode']],["is_del","=",0]])->find();
  277. if($good==false){
  278. return error_show(1004,"未找到商品数据");
  279. }
  280. $int= isset($good['cat_id']) && $good['cat_id'] !=0 ? made($good['cat_id']):[];
  281. $metal = \think\facade\Config::get("noble");
  282. $info['noble_metal']= isset($metal[$good['noble_metal']]) && $good['noble_metal'] !=''?$metal[$good['noble_metal']]:'';
  283. $info['noble_id']= isset($good['noble_metal']) && $good['noble_metal'] !='' ? $good['noble_metal']:"";
  284. $info['wsm_name']="";
  285. $info['file_name'] ='';
  286. if($info['file_url']){
  287. $file= basename($info['file_url']);
  288. $info['file_name'] =substr($file,0,strripos($file,"_"));
  289. }
  290. if($info['wsm_code']!=""){
  291. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  292. ->where(["a.wsm_code"=>$info['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  293. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  294. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  295. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  296. }
  297. $supplier =Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  298. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  299. $company =Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
  300. $info['company_name'] = isset($company['company'])?$company['company']:"";
  301. $info['can']=$int;
  302. return app_show(0,"获取成功",$info);
  303. }
  304. public function edit(){
  305. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  306. if($token==""){
  307. return error_show(101,'token不能为空');
  308. }
  309. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  310. if($id==""){
  311. return error_show(1001,'id不能为空');
  312. }
  313. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  314. if(empty($info)){
  315. return error_show(1002,'未找到数据');
  316. }
  317. $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  318. if($customer==""){
  319. return error_show(1004,"参数customer_code不能为空");
  320. }
  321. $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  322. if($supplier==""){
  323. return error_show(1004,"参数supplier_code不能为空");
  324. }
  325. $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  326. if($good_code==""){
  327. return error_show(1004,"参数good_code不能为空");
  328. }
  329. $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  330. if($good_num===""){
  331. return error_show(1004,"参数good_code不能为空");
  332. }
  333. $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  334. if($file_url===""){
  335. return error_show(1004,"参数file_url不能为空");
  336. }
  337. $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  338. if($mark==""){
  339. return error_show(1004,"参数remark不能为空");
  340. }
  341. $good =Db::name("good_basic")->where([["spuCode","=", $good_code],["is_del","=",0]])->find();
  342. if($good==false){
  343. return error_show(1004,"未找到商品数据");
  344. }
  345. // $data = GetUserInfo($token);
  346. // if((!empty($data) && $data['code']!=0) ||empty($data) ){
  347. // return error_show($data['code'],$data['message']);
  348. // }
  349. // $userinfo = $data['data'];
  350. $up = [
  351. "spuCode"=>$good_code,
  352. "good_name"=>$good['good_name'],
  353. "good_num"=>$good_num,
  354. // "skuCode"=>$good['skuCode'],
  355. "companyNo"=>$customer,
  356. "supplierNo"=>$supplier,
  357. "file_url"=>$file_url,
  358. "remark"=>$mark,
  359. "updatetime"=>date("Y-m-d H:i:s"),
  360. ];
  361. $in = Db::name("purchease")->where($info)->save($up);
  362. if($in){
  363. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"before_status"=>1, 'holder_id' => $info['apply_id']];
  364. ProcessOrder::AddProcess($this->post['token'],$order);
  365. $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"];
  366. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$up);
  367. return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
  368. }else{
  369. return error_show(1005,"更新失败");
  370. }
  371. }
  372. public function delete(){
  373. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  374. if($id==""){
  375. return error_show(1001,'id不能为空');
  376. }
  377. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  378. if(empty($info)){
  379. return error_show(1002,'未找到数据');
  380. }
  381. $info['is_del']=1;
  382. $info['updatetime']=date("Y-m-d H:i:s");
  383. $up = Db::name("purchease")->update($info);
  384. if($up){
  385. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status']];
  386. ProcessOrder::workdel($order);
  387. $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"delete"];
  388. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
  389. }
  390. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  391. }
  392. public function status(){
  393. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  394. if($id==""){
  395. return error_show(1001,'id不能为空');
  396. }
  397. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  398. if(empty($info)){
  399. return error_show(1002,'未找到数据');
  400. }
  401. $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
  402. if($status===""){
  403. return error_show(1001,'status不能为空');
  404. }
  405. $temp = $info['status'];
  406. $info['status']= $status;
  407. $info['updatetime']=date("Y-m-d H:i:s");
  408. $up = Db::name("purchease")->update($info);
  409. if($up){
  410. if($status==1){
  411. $supplier = Db::name('supplier')
  412. ->field('id,person,personid')
  413. ->where('code', $info['supplierNo'])
  414. ->findOrEmpty();
  415. $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp,'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
  416. }else $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp, 'holder_id' => $info['apply_id']];
  417. $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp, 'holder_id' => $info['apply_id']];
  418. ProcessOrder::AddProcess($this->post['token'],$order);
  419. $ste = ["order_code"=>$info['bk_code'],"status"=> $temp,"action_remark"=>'',"action_type"=>"status"];
  420. ActionLog::logAdd($this->post['token'],$ste,"BHD",$status,$info);
  421. return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
  422. }else{
  423. return error_show(1005,"更新失败");
  424. }
  425. }
  426. public function addFeed(){
  427. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  428. if($token==""){
  429. return error_show(101,'token不能为空');
  430. }
  431. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  432. if($id==""){
  433. return error_show(1001,'id不能为空');
  434. }
  435. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  436. if(empty($info)){
  437. return error_show(1002,'未找到备库数据');
  438. }
  439. if($info['status']!=1){
  440. return error_show(1002,'备库数据状态有误');
  441. }
  442. $num = isset($this->post['num']) && $this->post['num']!=="" ? intval($this->post['num']):"";
  443. if($num==''){
  444. return error_show(1002,'参数num 不能为空或零');
  445. }
  446. $expecttime = isset($this->post['expecttime'])&&$this->post['expecttime']!=''?$this->post['expecttime'] :"";
  447. if($expecttime==''){
  448. return error_show(1002,'参数expecttime 不能为空');
  449. }
  450. $wsm_type = isset($this->post['wsm_type'])&&$this->post['wsm_type']!="" ? intval($this->post['wsm_type']):"";
  451. if($wsm_type==""){
  452. return error_show(1002,'参数wsm_type 不能为空');
  453. }
  454. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  455. if($wsm_code==""){
  456. return error_show(1002,'参数wsm_code 不能为空');
  457. }
  458. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"wsm_type"=>$wsm_type,"is_del"=>0])->find();
  459. if(empty($wsminfo)){
  460. return error_show(1002,'未找到仓库数据');
  461. }
  462. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!="" ? trim($this->post['supplierNo']):"";
  463. if($supplierNo==""){
  464. return error_show(1002,'参数supplierNo 不能为空');
  465. }
  466. $supplie = Db::name("supplier")->where(['code'=>$supplierNo,"is_del"=>0])->find();
  467. if(empty($supplie)){
  468. return error_show(1002,'未找到供应商');
  469. }
  470. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=="" ? $this->post['good_price']:"";
  471. if($good_price===""){
  472. return error_show(1002,'参数good_price 不能为空');
  473. }
  474. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=="" ? $this->post['pakge_fee']:0;
  475. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=="" ? $this->post['cert_fee']:0;
  476. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=="" ? $this->post['open_fee']:0;
  477. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=="" ? $this->post['delivery_fee']:0;
  478. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=="" ? $this->post['mark_fee']:0;
  479. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=="" ? $this->post['teach_fee']:0;
  480. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=="" ? $this->post['nake_fee']:0;
  481. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=="" ? $this->post['demo_fee']:0;
  482. $weight = isset($this->post['weight'])&&$this->post['weight']!=="" ? $this->post['weight']:0;
  483. $diff_weight =isset($this->post['diff_weight'])&&$this->post['diff_weight']!=="" ? $this->post['diff_weight']:0;
  484. $diff_price =isset($this->post['diff_price'])&&$this->post['diff_price']!=="" ? $this->post['diff_price']:0;
  485. $remark =isset($this->post['remark'])&&$this->post['remark']!=="" ? $this->post['remark']:'';
  486. $data = GetUserInfo($token);
  487. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  488. return error_show($data['code'],$data['message']);
  489. }
  490. $userinfo = $data['data'];
  491. $data=[
  492. "bkcode"=>$info['bk_code'],
  493. "warehouse"=>$wsm_code,
  494. "wsm_type"=>$wsm_type,
  495. "num"=>$num,
  496. 'expecttime'=>$expecttime,
  497. 'supplier'=>isset($supplie) && $supplie['code']!=''? $supplie['code']:'',
  498. 'good_price'=>$good_price,
  499. 'pakge_fee'=>$pakge_fee,
  500. 'cert_fee'=>$cert_fee,
  501. 'open_fee'=>$open_fee,
  502. 'mark_fee'=>$mark_fee,
  503. 'teach_fee'=>$teach_fee,
  504. 'nake_fee'=>$nake_fee,
  505. 'demo_fee'=>$demo_fee,
  506. 'delivery_fee'=>$delivery_fee,
  507. 'weight'=>$weight,
  508. 'remark'=>$remark,
  509. 'diff_weight'=>$diff_weight,
  510. 'diff_price'=>$diff_price,
  511. 'purchaser'=>$userinfo['nickname'],
  512. 'purchaser_id'=>$userinfo['id'],
  513. "addtime"=>date("Y-m-d H:i:s"),
  514. "updatetime"=>date("Y-m-d H:i:s")
  515. ];
  516. Db::startTrans();
  517. try{
  518. $in = Db::name('purchease_feedback')->insert($data,true);
  519. if($in>0){
  520. $order=["order_type"=>'FKD',"order_code"=>$info['bk_code'],"order_id"=>$in, "order_status"=>0,"before_status"=>1];
  521. ProcessOrder::AddProcess($this->post['token'],$order);
  522. $ste = ["order_code"=>$info['bk_code'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  523. ActionLog::logAdd($this->post['token'],$ste,"FKD",0,$data);
  524. $temp=$info['status'];
  525. $info['status']=2;
  526. $info['wsm_code']=$wsm_code;
  527. $info['addtime']=date("Y-m-d H:i:s");
  528. $ood=Db::name('purchease')->save($info);
  529. if($ood){
  530. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'], "order_status"=>$info['status'],"before_status"=>$temp, 'holder_id' => $info['apply_id']];
  531. ProcessOrder::AddProcess($this->post['token'],$order);
  532. $ste = ["order_code"=>$info['bk_code'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
  533. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
  534. Db::commit();
  535. return app_show(0,"新建成功");
  536. }
  537. }
  538. Db::rollback();
  539. return error_show(1005,"新建失败");
  540. }catch (\Exception $e){
  541. Db::rollback();
  542. return error_show(1005,"新建失败");
  543. }
  544. // return $in ? app_show(0,"新建成功"):error_show(1005,"新建失败");
  545. }
  546. public function delFeed(){
  547. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  548. if($id==""){
  549. return error_show(1001,'id不能为空');
  550. }
  551. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  552. if(empty($feed)){
  553. return error_show(1004,'未找到数据');
  554. }
  555. if($feed['status']==1){
  556. return error_show(1004,'反馈数据已采用无法删除');
  557. }
  558. $feed['is_del']= 1;
  559. $feed['updatetime']=date("Y-m-d H:i:s");
  560. $up = Db::name("purchease_feedback")->update($feed);
  561. if($up){
  562. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$feed['id'], "order_status"=>0];
  563. ProcessOrder::workdel($order);
  564. $ste = ["order_code"=>$feed['bk_code'],"status"=>$feed['status'],"action_remark"=>'',"action_type"=>"delete"];
  565. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$feed);
  566. }
  567. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  568. }
  569. public function infoFeed(){
  570. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  571. if($id==""){
  572. return error_show(1001,'id不能为空');
  573. }
  574. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  575. if(empty($info)){
  576. return error_show(1002,'未找到备库数据');
  577. }
  578. $feed = Db::name("purchease_feedback")->where(['bkcode'=>$info['bk_code'],'is_del'=>0])->find();
  579. if(empty($feed)){
  580. return error_show(1004,'未找到反馈数据');
  581. }
  582. $feed['wsm_name']="";
  583. if($feed['warehouse']!=""){
  584. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  585. ->where(["a.wsm_code"=>$feed['warehouse']])->field("a.name as wsm_name,b.name,b.code")->find();
  586. $feed['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  587. $feed['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  588. $feed['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  589. }
  590. if($feed['supplier']!=""){
  591. $supplie = Db::name("supplier")->where(['code'=>$feed['supplier'],"is_del"=>0])->find();
  592. $feed['supplier_name'] =isset($supplie['name']) ? $supplie['name']:"";
  593. }
  594. return app_show(0,"获取成功",$feed);
  595. }
  596. public function changeFeed(){
  597. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  598. if($id==""){
  599. return error_show(1001,'id不能为空');
  600. }
  601. $feed = Db::name("purchease")->where(['id'=>$id,'is_del'=>0])->find();
  602. if(empty($feed)){
  603. return error_show(1004,'未找到数据');
  604. }
  605. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']) : "";
  606. if($status==""){
  607. return error_show(1001,'参数status 不能为空');
  608. }
  609. $remark = isset($this->post['remark'])&& $this->post['remark']!=='' ? trim($this->post['remark']) : "";
  610. Db::startTrans();
  611. try{
  612. $tem =$feed['status'];
  613. $feed['remark']= $remark;
  614. $feed['status']= $status;
  615. $feed['updatetime']=date("Y-m-d H:i:s");
  616. $up = Db::name("purchease")->update($feed);
  617. if($up){
  618. if ($feed['status'] == 1) {
  619. $supplier = Db::name('supplier')
  620. ->field('id,person,personid')
  621. ->where('code', $feed['supplierNo'])
  622. ->findOrEmpty();
  623. $order = ["order_type" => 'BHD', "order_code" => $feed['bk_code'], "order_id" => $feed['id'], "order_status" => $feed['status'], "before_status" => $tem, 'holder_id' => $feed['apply_id'], 'wait_id' => $supplier['personid'], 'wait_name' => $supplier['person']];
  624. } else $order = ["order_type" => 'BHD', "order_code" => $feed['bk_code'], "order_id" => $feed['id'], "order_status" => $feed['status'], "before_status" => $tem, 'holder_id' => $feed['apply_id']];
  625. ProcessOrder::AddProcess($this->post['token'], $order);
  626. $ste = ["order_code"=>$feed['bk_code'],"status"=>$tem,"action_remark"=>'',"action_type"=>"edit"];
  627. ActionLog::logAdd($this->post['token'],$ste,"BHD",$feed['status'],$feed);
  628. if($status==3){
  629. // $ware = Db::name("warehouse_addr")->where(["wsm_code"=>$feed['warehouse'],"is_del"=>0])->find();
  630. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  631. if(empty($purse)){
  632. Db::rollback();
  633. return error_show(1001,'未找到备库反馈数据');
  634. }
  635. $pe = $purse['status'];
  636. $purse['status']=1;
  637. $purse['addtime']=date("Y-m-d H:i:s");
  638. $up = Db::name("purchease_feedback")->save($purse);
  639. if($up==false){
  640. Db::rollback();
  641. return error_show(1001,'备库反馈数据状态修改失败');
  642. }
  643. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>$pe];
  644. ProcessOrder::AddProcess($this->post['token'],$order);
  645. $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"];
  646. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse);
  647. $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']])->find();
  648. $inw = makeNo("CG");
  649. $goodinfo=Db::name('good_basic')
  650. ->field('id,createrid,creater')
  651. ->where(['is_del'=>0,'spuCode'=>$feed['spuCode']])
  652. ->findOrEmpty();
  653. $data=[
  654. "bkcode"=>$purse['bkcode'],
  655. 'cgdNo'=>$inw,
  656. "wsm_code"=>$purse['warehouse'],
  657. "good_code"=>$feed['good_code'],
  658. "good_name"=>$feed['good_name'],
  659. "good_type_code"=>$feed['good_type_code'],
  660. "good_num"=>$feed['good_num'],
  661. "send_num"=>0,
  662. "wsend_num"=>$feed['good_num'],
  663. 'good_price'=>$purse['good_price'],
  664. "total_fee"=>$purse['good_price'],
  665. 'pakge_fee'=>$purse['pakge_fee'],
  666. 'cert_fee'=>$purse['cert_fee'],
  667. 'open_fee'=>$purse['open_fee'],
  668. 'mark_fee'=>$purse['mark_fee'],
  669. 'teach_fee'=>$purse['teach_fee'],
  670. 'nake_fee'=>$purse['nake_fee'],
  671. 'demo_fee'=>$purse['demo_fee'],
  672. 'delivery_fee'=>$purse['delivery_fee'],
  673. 'weight'=>$purse['weight'],
  674. 'diff_weight'=>$purse['diff_weight'],
  675. 'diff_fee'=>$purse['diff_price'],
  676. 'cgder_id'=>$purse['purchaser_id'],
  677. 'cgder'=>$purse['purchaser'],
  678. "remark"=>$purse['remark'],
  679. "status"=>0,
  680. 'supplierNo'=>$purse['supplier'],
  681. 'supplier_name'=>isset($supplier['name']) ? $supplier['name']:"",
  682. 'lasttime'=>$purse['expecttime'],
  683. "addtime"=>date("Y-m-d H:i:s"),
  684. "updatetime"=>date("Y-m-d H:i:s"),
  685. 'good_createrid' => $goodinfo['createrid'],
  686. 'good_creater' => $goodinfo['creater'],//商品的创建人
  687. ];
  688. $in= Db::name("purchease_order")->insert($data,true);
  689. if($in>0){
  690. $order=["order_type"=>'CGD',"order_code"=>$data['cgdNo'],"order_id"=>$in, "order_status"=>$data['status'],"before_status"=>0];
  691. ProcessOrder::AddProcess($this->post['token'],$order);
  692. $ste = ["order_code"=>$inw,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"];
  693. ActionLog::logAdd($this->post['token'],$ste,"CGD",$data['status'],$data);
  694. //将采购单数据塞入到队列中
  695. $push_data = json_encode([
  696. 'supplierNo' => $data['supplierNo'],
  697. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  698. 'data' => [
  699. 'cgdNo' => $data['cgdNo'],
  700. 'spuCode' => $feed['spuCode'],
  701. 'good_name' => $data['good_name'],
  702. 'good_num' => $data['good_num'],
  703. 'good_price' => $data['good_price'],
  704. 'total_fee' => $data['total_fee'],
  705. 'weight' => $data['weight'],
  706. 'addtime' => $data['addtime'],
  707. ],
  708. ], JSON_UNESCAPED_UNICODE);
  709. Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  710. Db::commit();
  711. return app_show(0,"更新成功",['cgdNo'=>$inw]);
  712. }
  713. }else{
  714. if($status==4){
  715. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  716. if(empty($purse)){
  717. Db::rollback();
  718. return error_show(1001,'未找到备库反馈数据');
  719. }
  720. $pe=$purse['status'];
  721. $purse['status']=2;
  722. $purse['addtime']=date("Y-m-d H:i:s");
  723. $up = Db::name("purchease_feedback")->save($purse);
  724. if($up==false){
  725. Db::rollback();
  726. return error_show(1001,'备库反馈数据状态修改失败');
  727. }
  728. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>1];
  729. ProcessOrder::AddProcess($this->post['token'],$order);
  730. $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"];
  731. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse);
  732. }
  733. Db::commit();
  734. return app_show(0,"更新成功");
  735. }
  736. }
  737. Db::rollback();
  738. return error_show(1004,"更新失败");
  739. }catch (\Exception $e){
  740. Db::rollback();
  741. return error_show(1005,$e->getMessage());
  742. }
  743. }
  744. public function addwsm(){
  745. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  746. if($id==""){
  747. return error_show(1001,'id不能为空');
  748. }
  749. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  750. if($info==false){
  751. return error_show(1002,'未找到备库数据');
  752. }
  753. $wsm= isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']) : "";
  754. if($wsm==""){
  755. return error_show(1004,"参数wsm_code不能为空");
  756. }
  757. $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm,"is_del"=>0])->find();
  758. if($wsminfo==false){
  759. return error_show(1004,"未找到仓库数据");
  760. }
  761. $info['wsm_code']=$wsm;
  762. $old_info_status = $info['status'];
  763. $info['status']=1;
  764. $info['updatetime']=date("y-m-d H;i:s");
  765. $up =Db::name("purchease")->save($info);
  766. if($up){
  767. //修改状态,添加待办
  768. ActionLog::logAdd($this->post['token'], [
  769. "order_code" => $info['bk_code'],//销售单code
  770. "status" => $old_info_status,//这里的status是之前的值
  771. "action_remark" => '',//备注
  772. "action_type" => "edit"//新建create,编辑edit,更改状态status
  773. ], "BHD", $info['status'], $info);
  774. $supplier = Db::name('supplier')
  775. ->field('id,person,personid')
  776. ->where('code', $info['supplierNo'])
  777. ->findOrEmpty();
  778. ProcessOrder::AddProcess($this->post['token'], [
  779. "order_type" => 'BHD',
  780. "order_code" => $info['bk_code'],//销售单code
  781. "order_id" => $info['id'],
  782. "order_status" => $info['status'],
  783. "before_status"=>$old_info_status,
  784. //'holder_id' => $info['apply_id'],
  785. 'wait_id' => $supplier['personid'],
  786. 'wait_name' => $supplier['person'],
  787. ]);
  788. return app_show(0,"备库单仓库选择成功");
  789. }else{
  790. return error_show(1004,"备库单仓库选择失败");
  791. }
  792. }
  793. //备库单生成采购单
  794. public function createCgd(){
  795. $bk_code=isset($this->post['bk_code'])&&$this->post['bk_code']!=="" ? trim($this->post['bk_code']):"";
  796. if($bk_code===""){
  797. return error_show(1004,"参数bk_code不能为空");
  798. }
  799. $info = Db::name("purchease")->where(["bk_code"=>$bk_code,"is_del"=>0])->find();
  800. if($info==false){
  801. return error_show(1002,'未找到备库数据');
  802. }
  803. $wsm_code =isset($this->post['wsm_code'])&&$this->post['wsm_code']!=="" ? trim($this->post['wsm_code']):'';
  804. if($wsm_code==""){
  805. return error_show(1002,'备库仓库不能为空');
  806. }
  807. $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  808. if($wsminfo==false){
  809. return error_show(1002,'备库仓库未找到');
  810. }
  811. $good =Db::name("good_basic")->where([["spuCode","=",$info['spuCode']],["is_del","=",0]])->find();
  812. if($good==false){
  813. return error_show(1004,"未找到商品数据");
  814. }
  815. $supplier=Db::name("supplier")->where(["code"=>$info['supplierNo'],"is_del"=>0])->find();
  816. if($supplier==false){
  817. return error_show(1004,"未找到供应商数据");
  818. }
  819. $goodnake =Db::name("good_nake")->where([["spuCode","=",$info['spuCode']],["is_del","=",0],["min_num","<=",
  820. $info['good_num']]])->order("min_num desc")->find();
  821. if($goodnake==false){
  822. return error_show(1004,"未找到成本数据");
  823. }
  824. $top_cat = made($good['cat_id']);
  825. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:"";
  826. if($good['is_gold_price']==1 && $top_cat_id==6){
  827. $gold = Db::name("gold_price1")->where(["type"=>$good['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
  828. ->find();
  829. // $weight = $good['noble_weight']*$info['good_num'];
  830. $sale_price = round($good['demo_fee'] / $info['good_num'] + $good['open_fee'] / $info['good_num'] + $good['noble_weight'] * $gold["price"] + $goodnake['cost_fee'] * $good['noble_weight'] + $goodnake['package_fee'] + $goodnake['mark_fee'] + $goodnake['cert_fee'] +$goodnake['nake_fee'] + $goodnake['delivery_fee'],2);
  831. $total_price = round($info['good_num']*$sale_price,2);
  832. }else{
  833. $sale_price = $goodnake['nake_total'];
  834. $total_price = round($info['good_num']*$sale_price,2);
  835. }
  836. $cgdCode = makeNo("CG");
  837. $cg =["cgdNo"=>$cgdCode,
  838. "bkcode"=>$bk_code,
  839. "wsm_code"=>$wsm_code,
  840. "cgder"=>$good['creater'],
  841. "cgder_id"=>$good['createrid'],
  842. "spuCode"=>$info['spuCode'],
  843. "good_name"=>$info['good_name'],
  844. "good_num"=>$info['good_num'],
  845. "good_price"=>$sale_price,
  846. "total_fee"=>$total_price,
  847. "pakge_fee"=>isset($goodnake['package_fee'])? $goodnake['package_fee']:0,
  848. "cert_fee"=>isset($goodnake['cert_fee'])? $goodnake['cert_fee']:0,
  849. "open_fee"=>$good['open_fee'],
  850. "delivery_fee"=>isset($goodnake['delivery_fee'])? $goodnake['delivery_fee']:0,
  851. "mark_fee"=>isset($goodnake['mark_fee'])? $goodnake['mark_fee']:0,
  852. "nake_fee"=>isset($goodnake['nake_fee'])? $goodnake['nake_fee']:0,
  853. "teach_fee"=>isset($goodnake['cost_fee'])? $goodnake['cost_fee']:0,
  854. "demo_fee"=>$good['demo_fee'],
  855. "diff_weight"=>"0",
  856. "diff_fee"=>"0",
  857. "gold_price"=>"0",
  858. "supplierNo"=>$info['supplierNo'],
  859. "supplier_name"=>$supplier['name'],
  860. "companyNo"=>$info['companyNo'],
  861. "send_status"=>1,
  862. "send_num"=>"0",
  863. "wsend_num"=>$info['good_num'],
  864. "weight"=>$good['noble_weight'],
  865. "remark"=>"",
  866. "status"=>0,//0表示初始化
  867. "lasttime"=>$info['lasttime'],
  868. "is_del"=>0,
  869. "order_type" => 1,//1备库
  870. "order_source" => 0,//0备库下单
  871. "good_type"=>1,
  872. "addtime"=>date("Y-m-d H:i:s"),
  873. "updatetime"=>date("Y-m-d H:i:s"),
  874. 'good_createrid' => $good['createrid'],
  875. 'good_creater' => $good['creater'],//商品创建人
  876. ];
  877. Db::startTrans();
  878. try{
  879. $up =Db::name("purchease_order")->insert($cg,true);
  880. if($up>0){
  881. $good = Db::name("good_stock")->where(["wsm_code" =>$wsm_code, "spuCode" => $info['spuCode'], "is_del" => 0])->find();
  882. if ($good == false) {
  883. $good = [
  884. "spuCode" => $info['spuCode'],
  885. "wsm_code" => $wsm_code,
  886. "usable_stock" => 0,
  887. "wait_out_stock" => 0,
  888. "wait_in_stock" => 0,
  889. "total_stock" => 0,
  890. "addtime" => date("Y-m-d H:i:s"),
  891. "updatetime" => date("Y-m-d H:i:s"),
  892. ];
  893. $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"];
  894. } else {
  895. $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"];
  896. }
  897. $good['wait_in_stock'] += $info['good_num'];
  898. $good['updatetime'] = date("Y-m-d H:i:s");
  899. $upd = Db::name("good_stock")->save($good);
  900. $good_data[] = ['good_log_code' => $cgdCode,"stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1,
  901. 'stock' => $info['good_num'], "stock_name" => "wait_in_stock"];
  902. if ($upd) {
  903. // 商品变动日志表,good_log_code字段存储采购单号
  904. $order = ["order_code" => $cgdCode, "status" => 0, "action_remark" => '', "action_type" => "create"];
  905. GoodLog::LogAdd($this->post['token'], $good_data, 'CGD');
  906. ActionLog::logAdd($this->post['token'], $order, "CGD", 0, $good);
  907. $process = ["order_code" => $cgdCode, "order_id" => $up, "order_status" => $cg['status'], "order_type" => 'CGD',"before_status"=>0,'holder_id'=>Db::name('supplier')->where(['code' => $cg['supplierNo'], 'is_del' => 0])->value('personid', 0)];
  908. ProcessOrder::AddProcess($this->post['token'], $process);
  909. $info['wsm_code'] = $wsm_code;
  910. $old_info_status = $info['status'];
  911. $info['status'] = 2;
  912. $info['updatetime'] = date("Y-m-d H:i:s");
  913. $bas = Db::name("purchease")->save($info);
  914. if ($bas) {
  915. //修改状态,添加待办
  916. ActionLog::logAdd($this->post['token'], [
  917. "order_code" => $info['bk_code'],//销售单code
  918. "status" => $old_info_status,//这里的status是之前的值
  919. "action_remark" => '',//备注
  920. "action_type" => "edit"//新建create,编辑edit,更改状态status
  921. ], "BHD", $info['status'], $info);
  922. ProcessOrder::AddProcess($this->post['token'], [
  923. "order_type" => 'BHD',
  924. "order_code" => $info['bk_code'],//销售单code
  925. "order_id" => $info['id'],
  926. "order_status" => $info['status'],
  927. "before_status"=> $old_info_status,
  928. 'holder_id' => $info['apply_id']
  929. ]);
  930. //维护台账记录
  931. Db::name('standing_book')->where('bk_code', $bk_code)->update([
  932. 'spuCode' => $cg['spuCode'],
  933. 'order_type' => $cg['order_type'],
  934. 'order_source' => $cg['order_source'],
  935. 'supplierNo' => $cg['supplierNo'],
  936. 'companyNo' => $cg['companyNo'],
  937. 'cgdNo' => $cg['cgdNo'],
  938. 'updatetime' => date('Y-m-d H:i:s'),
  939. ]);
  940. //将采购单数据塞入到队列中
  941. $push_data = json_encode([
  942. 'supplierNo' => $cg['supplierNo'],
  943. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  944. 'data' => [
  945. 'cgdNo' => $cg['cgdNo'],
  946. 'spuCode' => $cg['spuCode'],
  947. 'good_name' => $cg['good_name'],
  948. 'good_num' => $cg['good_num'],
  949. 'good_price' => $cg['good_price'],
  950. 'total_fee' => $cg['total_fee'],
  951. 'weight' => $cg['weight'],
  952. 'addtime' => $cg['addtime'],
  953. ],
  954. ], JSON_UNESCAPED_UNICODE);
  955. Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  956. Db::commit();
  957. return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
  958. }
  959. }
  960. // }
  961. }
  962. Db::rollback();
  963. return error_show(1004,"采购单新建失败");
  964. }catch (\Exception $e){
  965. Db::rollback();
  966. return error_show(1004,$e->getMessage());
  967. }
  968. }
  969. }