Resign.php 55 KB

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