Resign.php 53 KB

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