Resign.php 55 KB

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