Resign.php 53 KB

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