Resign.php 54 KB

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