Resign.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  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"=>$userinfo['id'],
  189. "apply_name"=>$userinfo['nickname'],
  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];
  195. ProcessOrder::AddProcess($token,$order);
  196. $ste = ["order_code"=>$bk_code,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  197. ActionLog::logAdd($token,$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']=$userinfo['id'];
  244. $info['apply_name']=$userinfo['nickname'];
  245. unset($info['id']);
  246. $in = Db::name("purchease")->insert($info,true);
  247. if($in>0){
  248. $order=["order_type"=>'BHD',"order_code"=>$bk_code,"order_id"=>$in,"order_status"=>1,"before_status"=>1];
  249. ProcessOrder::AddProcess($this->post['token'],$order);
  250. $ste = ["order_code"=>$bk_code,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  251. ActionLog::logAdd($this->post['token'],$ste,"BHD",1,$info);
  252. return app_show(0,"新建成功",['bk_code'=>$bk_code]);
  253. }else{
  254. return error_show(1005,"新建失败");
  255. }
  256. }
  257. /**
  258. * @return \think\response\Json|void
  259. * @throws \think\db\exception\DataNotFoundException
  260. * @throws \think\db\exception\DbException
  261. * @throws \think\db\exception\ModelNotFoundException
  262. */
  263. public function info(){
  264. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  265. if($id==""){
  266. return error_show(1001,'id不能为空');
  267. }
  268. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  269. if(empty($info)){
  270. return error_show(1002,'未找到数据');
  271. }
  272. $good =Db::name("good_basic")->where([["spuCode","=", $info['spuCode']],["is_del","=",0]])->find();
  273. if($good==false){
  274. return error_show(1004,"未找到商品数据");
  275. }
  276. $int= isset($good['cat_id']) && $good['cat_id'] !=0 ? made($good['cat_id']):[];
  277. $metal = \think\facade\Config::get("noble");
  278. $info['noble_metal']= isset($metal[$good['noble_metal']]) && $good['noble_metal'] !=''?$metal[$good['noble_metal']]:'';
  279. $info['noble_id']= isset($good['noble_metal']) && $good['noble_metal'] !='' ? $good['noble_metal']:"";
  280. $info['wsm_name']="";
  281. $info['file_name'] ='';
  282. if($info['file_url']){
  283. $file= basename($info['file_url']);
  284. $info['file_name'] =substr($file,0,strripos($file,"_"));
  285. }
  286. if($info['wsm_code']!=""){
  287. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  288. ->where(["a.wsm_code"=>$info['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  289. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  290. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  291. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  292. }
  293. $supplier =Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  294. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  295. $company =Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
  296. $info['company_name'] = isset($company['company'])?$company['company']:"";
  297. $info['can']=$int;
  298. return app_show(0,"获取成功",$info);
  299. }
  300. public function edit(){
  301. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  302. if($token==""){
  303. return error_show(101,'token不能为空');
  304. }
  305. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  306. if($id==""){
  307. return error_show(1001,'id不能为空');
  308. }
  309. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  310. if(empty($info)){
  311. return error_show(1002,'未找到数据');
  312. }
  313. $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  314. if($customer==""){
  315. return error_show(1004,"参数customer_code不能为空");
  316. }
  317. $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  318. if($supplier==""){
  319. return error_show(1004,"参数supplier_code不能为空");
  320. }
  321. $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  322. if($good_code==""){
  323. return error_show(1004,"参数good_code不能为空");
  324. }
  325. $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  326. if($good_num===""){
  327. return error_show(1004,"参数good_code不能为空");
  328. }
  329. $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  330. if($file_url===""){
  331. return error_show(1004,"参数file_url不能为空");
  332. }
  333. $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  334. if($mark==""){
  335. return error_show(1004,"参数remark不能为空");
  336. }
  337. $good =Db::name("good_basic")->where([["spuCode","=", $good_code],["is_del","=",0]])->find();
  338. if($good==false){
  339. return error_show(1004,"未找到商品数据");
  340. }
  341. $data = GetUserInfo($token);
  342. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  343. return error_show($data['code'],$data['message']);
  344. }
  345. $userinfo = $data['data'];
  346. $up = [
  347. "spuCode"=>$good_code,
  348. "good_name"=>$good['good_name'],
  349. "good_num"=>$good_num,
  350. // "skuCode"=>$good['skuCode'],
  351. "companyNo"=>$customer,
  352. "supplierNo"=>$supplier,
  353. "file_url"=>$file_url,
  354. "remark"=>$mark,
  355. "updatetime"=>date("Y-m-d H:i:s"),
  356. ];
  357. $in = Db::name("purchease")->where($info)->save($up);
  358. if($in){
  359. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"before_status"=>1];
  360. ProcessOrder::AddProcess($this->post['token'],$order);
  361. $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"];
  362. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$up);
  363. return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
  364. }else{
  365. return error_show(1005,"更新失败");
  366. }
  367. }
  368. public function delete(){
  369. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  370. if($id==""){
  371. return error_show(1001,'id不能为空');
  372. }
  373. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  374. if(empty($info)){
  375. return error_show(1002,'未找到数据');
  376. }
  377. $info['is_del']=1;
  378. $info['updatetime']=date("Y-m-d H:i:s");
  379. $up = Db::name("purchease")->update($info);
  380. if($up){
  381. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status']];
  382. ProcessOrder::workdel($order);
  383. $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"delete"];
  384. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
  385. }
  386. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  387. }
  388. public function status(){
  389. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  390. if($id==""){
  391. return error_show(1001,'id不能为空');
  392. }
  393. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  394. if(empty($info)){
  395. return error_show(1002,'未找到数据');
  396. }
  397. $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
  398. if($status===""){
  399. return error_show(1001,'status不能为空');
  400. }
  401. $temp = $info['status'];
  402. $info['status']= $status;
  403. $info['updatetime']=date("Y-m-d H:i:s");
  404. $up = Db::name("purchease")->update($info);
  405. if($up){
  406. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],
  407. "order_status"=>$status,"before_status"=>$temp];
  408. ProcessOrder::AddProcess($this->post['token'],$order);
  409. $ste = ["order_code"=>$info['bk_code'],"status"=> $temp,"action_remark"=>'',"action_type"=>"status"];
  410. ActionLog::logAdd($this->post['token'],$ste,"BHD",$status,$info);
  411. return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
  412. }else{
  413. return error_show(1005,"更新失败");
  414. }
  415. }
  416. public function addFeed(){
  417. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  418. if($token==""){
  419. return error_show(101,'token不能为空');
  420. }
  421. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  422. if($id==""){
  423. return error_show(1001,'id不能为空');
  424. }
  425. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  426. if(empty($info)){
  427. return error_show(1002,'未找到备库数据');
  428. }
  429. if($info['status']!=1){
  430. return error_show(1002,'备库数据状态有误');
  431. }
  432. $num = isset($this->post['num']) && $this->post['num']!=="" ? intval($this->post['num']):"";
  433. if($num==''){
  434. return error_show(1002,'参数num 不能为空或零');
  435. }
  436. $expecttime = isset($this->post['expecttime'])&&$this->post['expecttime']!=''?$this->post['expecttime'] :"";
  437. if($expecttime==''){
  438. return error_show(1002,'参数expecttime 不能为空');
  439. }
  440. $wsm_type = isset($this->post['wsm_type'])&&$this->post['wsm_type']!="" ? intval($this->post['wsm_type']):"";
  441. if($wsm_type==""){
  442. return error_show(1002,'参数wsm_type 不能为空');
  443. }
  444. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  445. if($wsm_code==""){
  446. return error_show(1002,'参数wsm_code 不能为空');
  447. }
  448. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"wsm_type"=>$wsm_type,"is_del"=>0])->find();
  449. if(empty($wsminfo)){
  450. return error_show(1002,'未找到仓库数据');
  451. }
  452. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!="" ? trim($this->post['supplierNo']):"";
  453. if($supplierNo==""){
  454. return error_show(1002,'参数supplierNo 不能为空');
  455. }
  456. $supplie = Db::name("supplier")->where(['code'=>$supplierNo,"is_del"=>0])->find();
  457. if(empty($supplie)){
  458. return error_show(1002,'未找到供应商');
  459. }
  460. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=="" ? $this->post['good_price']:"";
  461. if($good_price===""){
  462. return error_show(1002,'参数good_price 不能为空');
  463. }
  464. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=="" ? $this->post['pakge_fee']:0;
  465. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=="" ? $this->post['cert_fee']:0;
  466. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=="" ? $this->post['open_fee']:0;
  467. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=="" ? $this->post['delivery_fee']:0;
  468. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=="" ? $this->post['mark_fee']:0;
  469. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=="" ? $this->post['teach_fee']:0;
  470. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=="" ? $this->post['nake_fee']:0;
  471. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=="" ? $this->post['demo_fee']:0;
  472. $weight = isset($this->post['weight'])&&$this->post['weight']!=="" ? $this->post['weight']:0;
  473. $diff_weight =isset($this->post['diff_weight'])&&$this->post['diff_weight']!=="" ? $this->post['diff_weight']:0;
  474. $diff_price =isset($this->post['diff_price'])&&$this->post['diff_price']!=="" ? $this->post['diff_price']:0;
  475. $remark =isset($this->post['remark'])&&$this->post['remark']!=="" ? $this->post['remark']:'';
  476. $data = GetUserInfo($token);
  477. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  478. return error_show($data['code'],$data['message']);
  479. }
  480. $userinfo = $data['data'];
  481. $data=[
  482. "bkcode"=>$info['bk_code'],
  483. "warehouse"=>$wsm_code,
  484. "wsm_type"=>$wsm_type,
  485. "num"=>$num,
  486. 'expecttime'=>$expecttime,
  487. 'supplier'=>isset($supplie) && $supplie['code']!=''? $supplie['code']:'',
  488. 'good_price'=>$good_price,
  489. 'pakge_fee'=>$pakge_fee,
  490. 'cert_fee'=>$cert_fee,
  491. 'open_fee'=>$open_fee,
  492. 'mark_fee'=>$mark_fee,
  493. 'teach_fee'=>$teach_fee,
  494. 'nake_fee'=>$nake_fee,
  495. 'demo_fee'=>$demo_fee,
  496. 'delivery_fee'=>$delivery_fee,
  497. 'weight'=>$weight,
  498. 'remark'=>$remark,
  499. 'diff_weight'=>$diff_weight,
  500. 'diff_price'=>$diff_price,
  501. 'purchaser'=>$userinfo['nickname'],
  502. 'purchaser_id'=>$userinfo['id'],
  503. "addtime"=>date("Y-m-d H:i:s"),
  504. "updatetime"=>date("Y-m-d H:i:s")
  505. ];
  506. Db::startTrans();
  507. try{
  508. $in = Db::name('purchease_feedback')->insert($data,true);
  509. if($in>0){
  510. $order=["order_type"=>'FKD',"order_code"=>$info['bk_code'],"order_id"=>$in, "order_status"=>0,"before_status"=>1];
  511. ProcessOrder::AddProcess($this->post['token'],$order);
  512. $ste = ["order_code"=>$info['bk_code'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  513. ActionLog::logAdd($this->post['token'],$ste,"FKD",0,$data);
  514. $temp=$info['status'];
  515. $info['status']=2;
  516. $info['wsm_code']=$wsm_code;
  517. $info['addtime']=date("Y-m-d H:i:s");
  518. $ood=Db::name('purchease')->save($info);
  519. if($ood){
  520. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'], "order_status"=>$info['status'],"before_status"=>$temp];
  521. ProcessOrder::AddProcess($this->post['token'],$order);
  522. $ste = ["order_code"=>$info['bk_code'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
  523. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
  524. Db::commit();
  525. return app_show(0,"新建成功");
  526. }
  527. }
  528. Db::rollback();
  529. return error_show(1005,"新建失败");
  530. }catch (\Exception $e){
  531. Db::rollback();
  532. return error_show(1005,"新建失败");
  533. }
  534. // return $in ? app_show(0,"新建成功"):error_show(1005,"新建失败");
  535. }
  536. public function delFeed(){
  537. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  538. if($id==""){
  539. return error_show(1001,'id不能为空');
  540. }
  541. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  542. if(empty($feed)){
  543. return error_show(1004,'未找到数据');
  544. }
  545. if($feed['status']==1){
  546. return error_show(1004,'反馈数据已采用无法删除');
  547. }
  548. $feed['is_del']= 1;
  549. $feed['updatetime']=date("Y-m-d H:i:s");
  550. $up = Db::name("purchease_feedback")->update($feed);
  551. if($up){
  552. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$feed['id'], "order_status"=>0];
  553. ProcessOrder::workdel($order);
  554. $ste = ["order_code"=>$feed['bk_code'],"status"=>$feed['status'],"action_remark"=>'',"action_type"=>"delete"];
  555. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$feed);
  556. }
  557. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  558. }
  559. public function infoFeed(){
  560. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  561. if($id==""){
  562. return error_show(1001,'id不能为空');
  563. }
  564. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  565. if(empty($info)){
  566. return error_show(1002,'未找到备库数据');
  567. }
  568. $feed = Db::name("purchease_feedback")->where(['bkcode'=>$info['bk_code'],'is_del'=>0])->find();
  569. if(empty($feed)){
  570. return error_show(1004,'未找到反馈数据');
  571. }
  572. $feed['wsm_name']="";
  573. if($feed['warehouse']!=""){
  574. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  575. ->where(["a.wsm_code"=>$feed['warehouse']])->field("a.name as wsm_name,b.name,b.code")->find();
  576. $feed['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  577. $feed['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  578. $feed['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  579. }
  580. if($feed['supplier']!=""){
  581. $supplie = Db::name("supplier")->where(['code'=>$feed['supplier'],"is_del"=>0])->find();
  582. $feed['supplier_name'] =isset($supplie['name']) ? $supplie['name']:"";
  583. }
  584. return app_show(0,"获取成功",$feed);
  585. }
  586. public function changeFeed(){
  587. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  588. if($id==""){
  589. return error_show(1001,'id不能为空');
  590. }
  591. $feed = Db::name("purchease")->where(['id'=>$id,'is_del'=>0])->find();
  592. if(empty($feed)){
  593. return error_show(1004,'未找到数据');
  594. }
  595. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']) : "";
  596. if($status==""){
  597. return error_show(1001,'参数status 不能为空');
  598. }
  599. $remark = isset($this->post['remark'])&& $this->post['remark']!=='' ? trim($this->post['remark']) : "";
  600. Db::startTrans();
  601. try{
  602. $tem =$feed['status'];
  603. $feed['remark']= $remark;
  604. $feed['status']= $status;
  605. $feed['updatetime']=date("Y-m-d H:i:s");
  606. $up = Db::name("purchease")->update($feed);
  607. if($up){
  608. $order=["order_type"=>'BHD',"order_code"=>$feed['bk_code'],"order_id"=>$feed['id'], "order_status"=>$feed['status'],"before_status"=>$tem];
  609. ProcessOrder::AddProcess($this->post['token'],$order);
  610. $ste = ["order_code"=>$feed['bk_code'],"status"=>$tem,"action_remark"=>'',"action_type"=>"edit"];
  611. ActionLog::logAdd($this->post['token'],$ste,"BHD",$feed['status'],$feed);
  612. if($status==3){
  613. // $ware = Db::name("warehouse_addr")->where(["wsm_code"=>$feed['warehouse'],"is_del"=>0])->find();
  614. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  615. if(empty($purse)){
  616. Db::rollback();
  617. return error_show(1001,'未找到备库反馈数据');
  618. }
  619. $pe = $purse['status'];
  620. $purse['status']=1;
  621. $purse['addtime']=date("Y-m-d H:i:s");
  622. $up = Db::name("purchease_feedback")->save($purse);
  623. if($up==false){
  624. Db::rollback();
  625. return error_show(1001,'备库反馈数据状态修改失败');
  626. }
  627. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>$pe];
  628. ProcessOrder::AddProcess($this->post['token'],$order);
  629. $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"];
  630. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse);
  631. $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']])->find();
  632. $inw = makeNo("CG");
  633. $goodinfo=Db::name('good_basic')
  634. ->field('id,createrid,creater')
  635. ->where(['is_del'=>0,'spuCode'=>$feed['spuCode']])
  636. ->findOrEmpty();
  637. $data=[
  638. "bkcode"=>$purse['bkcode'],
  639. 'cgdNo'=>$inw,
  640. "wsm_code"=>$purse['warehouse'],
  641. "good_code"=>$feed['good_code'],
  642. "good_name"=>$feed['good_name'],
  643. "good_type_code"=>$feed['good_type_code'],
  644. "good_num"=>$feed['good_num'],
  645. "send_num"=>0,
  646. "wsend_num"=>$feed['good_num'],
  647. 'good_price'=>$purse['good_price'],
  648. "total_fee"=>$purse['good_price'],
  649. 'pakge_fee'=>$purse['pakge_fee'],
  650. 'cert_fee'=>$purse['cert_fee'],
  651. 'open_fee'=>$purse['open_fee'],
  652. 'mark_fee'=>$purse['mark_fee'],
  653. 'teach_fee'=>$purse['teach_fee'],
  654. 'nake_fee'=>$purse['nake_fee'],
  655. 'demo_fee'=>$purse['demo_fee'],
  656. 'delivery_fee'=>$purse['delivery_fee'],
  657. 'weight'=>$purse['weight'],
  658. 'diff_weight'=>$purse['diff_weight'],
  659. 'diff_fee'=>$purse['diff_price'],
  660. 'cgder_id'=>$purse['purchaser_id'],
  661. 'cgder'=>$purse['purchaser'],
  662. "remark"=>$purse['remark'],
  663. "status"=>0,
  664. 'supplierNo'=>$purse['supplier'],
  665. 'supplier_name'=>isset($supplier['name']) ? $supplier['name']:"",
  666. 'lasttime'=>$purse['expecttime'],
  667. "addtime"=>date("Y-m-d H:i:s"),
  668. "updatetime"=>date("Y-m-d H:i:s"),
  669. 'good_createrid' => $goodinfo['createrid'],
  670. 'good_creater' => $goodinfo['creater'],//商品的创建人
  671. ];
  672. $in= Db::name("purchease_order")->insert($data,true);
  673. if($in>0){
  674. $order=["order_type"=>'CGD',"order_code"=>$data['cgdNo'],"order_id"=>$in, "order_status"=>$data['status'],"before_status"=>0];
  675. ProcessOrder::AddProcess($this->post['token'],$order);
  676. $ste = ["order_code"=>$inw,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"];
  677. ActionLog::logAdd($this->post['token'],$ste,"CGD",$data['status'],$data);
  678. //将采购单数据塞入到队列中
  679. $push_data = json_encode([
  680. 'supplierNo' => $data['supplierNo'],
  681. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  682. 'data' => [
  683. 'cgdNo' => $data['cgdNo'],
  684. 'spuCode' => $feed['spuCode'],
  685. 'good_name' => $data['good_name'],
  686. 'good_num' => $data['good_num'],
  687. 'good_price' => $data['good_price'],
  688. 'total_fee' => $data['total_fee'],
  689. 'weight' => $data['weight'],
  690. 'addtime' => $data['addtime'],
  691. ],
  692. ], JSON_UNESCAPED_UNICODE);
  693. Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  694. Db::commit();
  695. return app_show(0,"更新成功",['cgdNo'=>$inw]);
  696. }
  697. }else{
  698. if($status==4){
  699. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  700. if(empty($purse)){
  701. Db::rollback();
  702. return error_show(1001,'未找到备库反馈数据');
  703. }
  704. $pe=$purse['status'];
  705. $purse['status']=2;
  706. $purse['addtime']=date("Y-m-d H:i:s");
  707. $up = Db::name("purchease_feedback")->save($purse);
  708. if($up==false){
  709. Db::rollback();
  710. return error_show(1001,'备库反馈数据状态修改失败');
  711. }
  712. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>1];
  713. ProcessOrder::AddProcess($this->post['token'],$order);
  714. $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"];
  715. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse);
  716. }
  717. Db::commit();
  718. return app_show(0,"更新成功");
  719. }
  720. }
  721. Db::rollback();
  722. return error_show(1004,"更新失败");
  723. }catch (\Exception $e){
  724. Db::rollback();
  725. return error_show(1005,$e->getMessage());
  726. }
  727. }
  728. public function addwsm(){
  729. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  730. if($id==""){
  731. return error_show(1001,'id不能为空');
  732. }
  733. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  734. if($info==false){
  735. return error_show(1002,'未找到备库数据');
  736. }
  737. $wsm= isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']) : "";
  738. if($wsm==""){
  739. return error_show(1004,"参数wsm_code不能为空");
  740. }
  741. $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm,"is_del"=>0])->find();
  742. if($wsminfo==false){
  743. return error_show(1004,"未找到仓库数据");
  744. }
  745. $info['wsm_code']=$wsm;
  746. $old_info_status = $info['status'];
  747. $info['status']=1;
  748. $info['updatetime']=date("y-m-d H;i:s");
  749. $up =Db::name("purchease")->save($info);
  750. if($up){
  751. //修改状态,添加待办
  752. ActionLog::logAdd($this->post['token'], [
  753. "order_code" => $info['bk_code'],//销售单code
  754. "status" => $old_info_status,//这里的status是之前的值
  755. "action_remark" => '',//备注
  756. "action_type" => "edit"//新建create,编辑edit,更改状态status
  757. ], "BHD", $info['status'], $info);
  758. ProcessOrder::AddProcess($this->post['token'], [
  759. "order_type" => 'BHD',
  760. "order_code" => $info['bk_code'],//销售单code
  761. "order_id" => $info['id'],
  762. "order_status" => $info['status'],"before_status"=>$old_info_status
  763. ]);
  764. return app_show(0,"备库单仓库选择成功");
  765. }else{
  766. return error_show(1004,"备库单仓库选择失败");
  767. }
  768. }
  769. //备库单生成采购单
  770. public function createCgd(){
  771. $bk_code=isset($this->post['bk_code'])&&$this->post['bk_code']!=="" ? trim($this->post['bk_code']):"";
  772. if($bk_code===""){
  773. return error_show(1004,"参数bk_code不能为空");
  774. }
  775. $info = Db::name("purchease")->where(["bk_code"=>$bk_code,"is_del"=>0])->find();
  776. if($info==false){
  777. return error_show(1002,'未找到备库数据');
  778. }
  779. $wsm_code =isset($this->post['wsm_code'])&&$this->post['wsm_code']!=="" ? trim($this->post['wsm_code']):'';
  780. if($wsm_code==""){
  781. return error_show(1002,'备库仓库不能为空');
  782. }
  783. $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  784. if($wsminfo==false){
  785. return error_show(1002,'备库仓库未找到');
  786. }
  787. $good =Db::name("good_basic")->where([["spuCode","=",$info['spuCode']],["is_del","=",0]])->find();
  788. if($good==false){
  789. return error_show(1004,"未找到商品数据");
  790. }
  791. $supplier=Db::name("supplier")->where(["code"=>$info['supplierNo'],"is_del"=>0])->find();
  792. if($supplier==false){
  793. return error_show(1004,"未找到供应商数据");
  794. }
  795. $goodnake =Db::name("good_nake")->where([["spuCode","=",$info['spuCode']],["is_del","=",0],["min_num","<=",
  796. $info['good_num']]])->order("min_num desc")->find();
  797. if($goodnake==false){
  798. return error_show(1004,"未找到成本数据");
  799. }
  800. $top_cat = made($good['cat_id']);
  801. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:"";
  802. if($good['is_gold_price']==1 && $top_cat_id==6){
  803. $gold = Db::name("gold_price1")->where(["type"=>$good['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
  804. ->find();
  805. // $weight = $good['noble_weight']*$info['good_num'];
  806. $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);
  807. $total_price = round($info['good_num']*$sale_price,2);
  808. }else{
  809. $sale_price = $goodnake['nake_total'];
  810. $total_price = round($info['good_num']*$sale_price,2);
  811. }
  812. $cgdCode = makeNo("CG");
  813. $cg =["cgdNo"=>$cgdCode,
  814. "bkcode"=>$bk_code,
  815. "wsm_code"=>$wsm_code,
  816. "cgder"=>$good['creater'],
  817. "cgder_id"=>$good['createrid'],
  818. "spuCode"=>$info['spuCode'],
  819. "good_name"=>$info['good_name'],
  820. "good_num"=>$info['good_num'],
  821. "good_price"=>$sale_price,
  822. "total_fee"=>$total_price,
  823. "pakge_fee"=>isset($goodnake['package_fee'])? $goodnake['package_fee']:0,
  824. "cert_fee"=>isset($goodnake['cert_fee'])? $goodnake['cert_fee']:0,
  825. "open_fee"=>$good['open_fee'],
  826. "delivery_fee"=>isset($goodnake['delivery_fee'])? $goodnake['delivery_fee']:0,
  827. "mark_fee"=>isset($goodnake['mark_fee'])? $goodnake['mark_fee']:0,
  828. "nake_fee"=>isset($goodnake['nake_fee'])? $goodnake['nake_fee']:0,
  829. "teach_fee"=>isset($goodnake['cost_fee'])? $goodnake['cost_fee']:0,
  830. "demo_fee"=>$good['demo_fee'],
  831. "diff_weight"=>"0",
  832. "diff_fee"=>"0",
  833. "gold_price"=>"0",
  834. "supplierNo"=>$info['supplierNo'],
  835. "supplier_name"=>$supplier['name'],
  836. "companyNo"=>$info['companyNo'],
  837. "send_status"=>1,
  838. "send_num"=>"0",
  839. "wsend_num"=>$info['good_num'],
  840. "weight"=>$good['noble_weight'],
  841. "remark"=>"",
  842. "status"=>0,//0表示初始化
  843. "lasttime"=>$info['lasttime'],
  844. "is_del"=>0,
  845. "order_type" => 1,//1备库
  846. "order_source" => 0,//0备库下单
  847. "good_type"=>1,
  848. "addtime"=>date("Y-m-d H:i:s"),
  849. "updatetime"=>date("Y-m-d H:i:s"),
  850. 'good_createrid' => $good['createrid'],
  851. 'good_creater' => $good['creater'],//商品创建人
  852. ];
  853. Db::startTrans();
  854. try{
  855. $up =Db::name("purchease_order")->insert($cg,true);
  856. if($up>0){
  857. $good = Db::name("good_stock")->where(["wsm_code" =>$wsm_code, "spuCode" => $info['spuCode'], "is_del" => 0])->find();
  858. if ($good == false) {
  859. $good = [
  860. "spuCode" => $info['spuCode'],
  861. "wsm_code" => $wsm_code,
  862. "usable_stock" => 0,
  863. "wait_out_stock" => 0,
  864. "wait_in_stock" => 0,
  865. "total_stock" => 0,
  866. "addtime" => date("Y-m-d H:i:s"),
  867. "updatetime" => date("Y-m-d H:i:s"),
  868. ];
  869. $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"];
  870. } else {
  871. $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"];
  872. }
  873. $good['wait_in_stock'] += $info['good_num'];
  874. $good['updatetime'] = date("Y-m-d H:i:s");
  875. $upd = Db::name("good_stock")->save($good);
  876. $good_data[] = ['good_log_code' => $cgdCode,"stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1,
  877. 'stock' => $info['good_num'], "stock_name" => "wait_in_stock"];
  878. if ($upd) {
  879. // 商品变动日志表,good_log_code字段存储采购单号
  880. $order = ["order_code" => $cgdCode, "status" => 0, "action_remark" => '', "action_type" => "create"];
  881. GoodLog::LogAdd($this->post['token'], $good_data, 'CGD');
  882. ActionLog::logAdd($this->post['token'], $order, "CGD", 0, $good);
  883. $process = ["order_code" => $cgdCode, "order_id" => $up, "order_status" => $cg['status'], "order_type" => 'CGD',"before_status"=>0];
  884. ProcessOrder::AddProcess($this->post['token'], $process);
  885. $info['wsm_code'] = $wsm_code;
  886. $old_info_status = $info['status'];
  887. $info['status'] = 2;
  888. $info['updatetime'] = date("Y-m-d H:i:s");
  889. $bas = Db::name("purchease")->save($info);
  890. if ($bas) {
  891. //修改状态,添加待办
  892. ActionLog::logAdd($this->post['token'], [
  893. "order_code" => $info['bk_code'],//销售单code
  894. "status" => $old_info_status,//这里的status是之前的值
  895. "action_remark" => '',//备注
  896. "action_type" => "edit"//新建create,编辑edit,更改状态status
  897. ], "BHD", $info['status'], $info);
  898. ProcessOrder::AddProcess($this->post['token'], [
  899. "order_type" => 'BHD',
  900. "order_code" => $info['bk_code'],//销售单code
  901. "order_id" => $info['id'],
  902. "order_status" => $info['status'],"before_status"=> $old_info_status
  903. ]);
  904. //维护台账记录
  905. Db::name('standing_book')->where('bk_code', $bk_code)->update([
  906. 'spuCode' => $cg['spuCode'],
  907. 'order_type' => $cg['order_type'],
  908. 'order_source' => $cg['order_source'],
  909. 'supplierNo' => $cg['supplierNo'],
  910. 'companyNo' => $cg['companyNo'],
  911. 'cgdNo' => $cg['cgdNo'],
  912. 'updatetime' => date('Y-m-d H:i:s'),
  913. ]);
  914. //将采购单数据塞入到队列中
  915. $push_data = json_encode([
  916. 'supplierNo' => $cg['supplierNo'],
  917. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  918. 'data' => [
  919. 'cgdNo' => $cg['cgdNo'],
  920. 'spuCode' => $cg['spuCode'],
  921. 'good_name' => $cg['good_name'],
  922. 'good_num' => $cg['good_num'],
  923. 'good_price' => $cg['good_price'],
  924. 'total_fee' => $cg['total_fee'],
  925. 'weight' => $cg['weight'],
  926. 'addtime' => $cg['addtime'],
  927. ],
  928. ], JSON_UNESCAPED_UNICODE);
  929. Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  930. Db::commit();
  931. return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
  932. }
  933. }
  934. // }
  935. }
  936. Db::rollback();
  937. return error_show(1004,"采购单新建失败");
  938. }catch (\Exception $e){
  939. Db::rollback();
  940. return error_show(1004,$e->getMessage());
  941. }
  942. }
  943. }