Resign.php 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  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. $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= 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. $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= new \app\admin\common\User();
  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 = new \app\admin\common\User();
  298. if($info['wsm_code']!=""){
  299. $wsmcode = Db::name("warehouse_info")->where(["wsm_code"=>$info['wsm_code']])->field("name as wsm_name,supplierNo")->find();
  300. $tmpd = $userCommon->handle('getCodeAndName', ['code' =>$wsmcode['supplierNo']]);
  301. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  302. $info['wsm_supplier'] =$tmpd['data'][$wsmcode['supplierNo']]??"";
  303. $info['wsm_supplierNo'] =$wsmcode['supplierNo']??"";
  304. }
  305. // $supplier =Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  306. $tmp = $userCommon->handle('getCodeAndName', ['code' =>[$info['companyNo'],$info['supplierNo']]]);
  307. if (!isset($tmp['code']) || $tmp['code'] != 0) return json_show($tmp['code'], $tmp['message'], $tmp['data']);
  308. // $company =Db::name("business")->where(["companyNo"=>$info['companyNo']])->find();
  309. $info['company_name'] = $tmp['data'][$info['companyNo']] ?? '';
  310. $info['supplier_name'] = $tmp['data'][$info['supplierNo']] ?? '';
  311. $info['can']=$int;
  312. return app_show(0,"获取成功",$info);
  313. }
  314. public function edit(){
  315. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  316. if($token==""){
  317. return error_show(101,'token不能为空');
  318. }
  319. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  320. if($id==""){
  321. return error_show(1001,'id不能为空');
  322. }
  323. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  324. if(empty($info)){
  325. return error_show(1002,'未找到数据');
  326. }
  327. $customer = isset($this->post['customer_code'])&&$this->post['customer_code']!="" ?trim($this->post['customer_code']):"";
  328. if($customer==""){
  329. return error_show(1004,"参数customer_code不能为空");
  330. }
  331. $supplier = isset($this->post['supplier_code'])&&$this->post['supplier_code']!="" ?trim($this->post['supplier_code']):"";
  332. if($supplier==""){
  333. return error_show(1004,"参数supplier_code不能为空");
  334. }
  335. $good_code = isset($this->post['good_code']) && $this->post['good_code']!=""?trim($this->post['good_code']):"";
  336. if($good_code==""){
  337. return error_show(1004,"参数good_code不能为空");
  338. }
  339. $good_num = isset($this->post['good_num'])&& $this->post['good_num']!==""? intval($this->post['good_num']):"";
  340. if($good_num===""){
  341. return error_show(1004,"参数good_code不能为空");
  342. }
  343. $file_url = isset($this->post['file_url'])&& $this->post['file_url']!==""? trim($this->post['file_url']):"";
  344. if($file_url===""){
  345. return error_show(1004,"参数file_url不能为空");
  346. }
  347. $mark =isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
  348. if($mark==""){
  349. return error_show(1004,"参数remark不能为空");
  350. }
  351. $good =Db::name("good_basic")->where([["spuCode","=", $good_code],["is_del","=",0]])->find();
  352. if($good==false){
  353. return error_show(1004,"未找到商品数据");
  354. }
  355. // $data = GetUserInfo($token);
  356. // if((!empty($data) && $data['code']!=0) ||empty($data) ){
  357. // return error_show($data['code'],$data['message']);
  358. // }
  359. // $userinfo = $data['data'];
  360. $up = [
  361. "spuCode"=>$good_code,
  362. "good_name"=>$good['good_name'],
  363. "good_num"=>$good_num,
  364. // "skuCode"=>$good['skuCode'],
  365. "companyNo"=>$customer,
  366. "supplierNo"=>$supplier,
  367. "file_url"=>$file_url,
  368. "remark"=>$mark,
  369. "updatetime"=>date("Y-m-d H:i:s"),
  370. ];
  371. $in = Db::name("purchease")->where($info)->save($up);
  372. if($in){
  373. $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']];
  374. ProcessOrder::AddProcess($this->post['token'],$order);
  375. $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"edit"];
  376. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$up);
  377. return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
  378. }else{
  379. return error_show(1005,"更新失败");
  380. }
  381. }
  382. public function delete(){
  383. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  384. if($id==""){
  385. return error_show(1001,'id不能为空');
  386. }
  387. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  388. if(empty($info)){
  389. return error_show(1002,'未找到数据');
  390. }
  391. $info['is_del']=1;
  392. $info['updatetime']=date("Y-m-d H:i:s");
  393. $up = Db::name("purchease")->update($info);
  394. if($up){
  395. $order=["order_type"=>'BHD',"order_code"=>$info['bk_code'],"order_id"=>$info['id'],"order_status"=>$info['status']];
  396. ProcessOrder::workdel($order);
  397. $ste = ["order_code"=>$info['bk_code'],"status"=>$info['status'],"action_remark"=>'',"action_type"=>"delete"];
  398. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
  399. }
  400. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  401. }
  402. public function status(){
  403. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  404. if($id==""){
  405. return error_show(1001,'id不能为空');
  406. }
  407. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  408. if(empty($info)){
  409. return error_show(1002,'未找到数据');
  410. }
  411. $userCommon= new \app\admin\common\User();
  412. $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]);
  413. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在");
  414. $holder_id=$supplier_temp['data']['personid']??0;
  415. $holder_name=$supplier_temp['data']['person']??0;
  416. $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
  417. if($status===""){
  418. return error_show(1001,'status不能为空');
  419. }
  420. $temp = $info['status'];
  421. $info['status']= $status;
  422. $info['updatetime']=date("Y-m-d H:i:s");
  423. $up = Db::name("purchease")->update($info);
  424. if($up){
  425. if($status==1){
  426. $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];
  427. }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']];
  428. $order = ["order_type" => 'BHD', "order_code" => $info['bk_code'], "order_id" => $info['id'], "order_status" => $status, "before_status" => $temp, 'holder_id' => $info['apply_id']];
  429. ProcessOrder::AddProcess($this->post['token'],$order);
  430. $ste = ["order_code"=>$info['bk_code'],"status"=> $temp,"action_remark"=>'',"action_type"=>"status"];
  431. ActionLog::logAdd($this->post['token'],$ste,"BHD",$status,$info);
  432. return app_show(0,"更新成功",['bk_code'=>$info['bk_code']]);
  433. }else{
  434. return error_show(1005,"更新失败");
  435. }
  436. }
  437. //废弃
  438. public function addFeed(){
  439. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  440. if($token==""){
  441. return error_show(101,'token不能为空');
  442. }
  443. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  444. if($id==""){
  445. return error_show(1001,'id不能为空');
  446. }
  447. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  448. if(empty($info)){
  449. return error_show(1002,'未找到备库数据');
  450. }
  451. if($info['status']!=1){
  452. return error_show(1002,'备库数据状态有误');
  453. }
  454. $num = isset($this->post['num']) && $this->post['num']!=="" ? intval($this->post['num']):"";
  455. if($num==''){
  456. return error_show(1002,'参数num 不能为空或零');
  457. }
  458. $expecttime = isset($this->post['expecttime'])&&$this->post['expecttime']!=''?$this->post['expecttime'] :"";
  459. if($expecttime==''){
  460. return error_show(1002,'参数expecttime 不能为空');
  461. }
  462. $wsm_type = isset($this->post['wsm_type'])&&$this->post['wsm_type']!="" ? intval($this->post['wsm_type']):"";
  463. if($wsm_type==""){
  464. return error_show(1002,'参数wsm_type 不能为空');
  465. }
  466. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  467. if($wsm_code==""){
  468. return error_show(1002,'参数wsm_code 不能为空');
  469. }
  470. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"wsm_type"=>$wsm_type,"is_del"=>0])->find();
  471. if(empty($wsminfo)){
  472. return error_show(1002,'未找到仓库数据');
  473. }
  474. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!="" ? trim($this->post['supplierNo']):"";
  475. if($supplierNo==""){
  476. return error_show(1002,'参数supplierNo 不能为空');
  477. }
  478. $supplie = Db::name("supplier")->where(['code'=>$supplierNo,"is_del"=>0])->find();//废弃
  479. if(empty($supplie)){
  480. return error_show(1002,'未找到供应商');
  481. }
  482. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=="" ? $this->post['good_price']:"";
  483. if($good_price===""){
  484. return error_show(1002,'参数good_price 不能为空');
  485. }
  486. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=="" ? $this->post['pakge_fee']:0;
  487. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=="" ? $this->post['cert_fee']:0;
  488. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=="" ? $this->post['open_fee']:0;
  489. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=="" ? $this->post['delivery_fee']:0;
  490. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=="" ? $this->post['mark_fee']:0;
  491. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=="" ? $this->post['teach_fee']:0;
  492. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=="" ? $this->post['nake_fee']:0;
  493. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=="" ? $this->post['demo_fee']:0;
  494. $weight = isset($this->post['weight'])&&$this->post['weight']!=="" ? $this->post['weight']:0;
  495. $diff_weight =isset($this->post['diff_weight'])&&$this->post['diff_weight']!=="" ? $this->post['diff_weight']:0;
  496. $diff_price =isset($this->post['diff_price'])&&$this->post['diff_price']!=="" ? $this->post['diff_price']:0;
  497. $remark =isset($this->post['remark'])&&$this->post['remark']!=="" ? $this->post['remark']:'';
  498. $data = GetUserInfo($token);
  499. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  500. return error_show($data['code'],$data['message']);
  501. }
  502. $userinfo = $data['data'];
  503. $data=[
  504. "bkcode"=>$info['bk_code'],
  505. "warehouse"=>$wsm_code,
  506. "wsm_type"=>$wsm_type,
  507. "num"=>$num,
  508. 'expecttime'=>$expecttime,
  509. 'supplier'=>isset($supplie) && $supplie['code']!=''? $supplie['code']:'',
  510. 'good_price'=>$good_price,
  511. 'pakge_fee'=>$pakge_fee,
  512. 'cert_fee'=>$cert_fee,
  513. 'open_fee'=>$open_fee,
  514. 'mark_fee'=>$mark_fee,
  515. 'teach_fee'=>$teach_fee,
  516. 'nake_fee'=>$nake_fee,
  517. 'demo_fee'=>$demo_fee,
  518. 'delivery_fee'=>$delivery_fee,
  519. 'weight'=>$weight,
  520. 'remark'=>$remark,
  521. 'diff_weight'=>$diff_weight,
  522. 'diff_price'=>$diff_price,
  523. 'purchaser'=>$userinfo['nickname'],
  524. 'purchaser_id'=>$userinfo['id'],
  525. "addtime"=>date("Y-m-d H:i:s"),
  526. "updatetime"=>date("Y-m-d H:i:s")
  527. ];
  528. Db::startTrans();
  529. try{
  530. $in = Db::name('purchease_feedback')->insert($data,true);
  531. if($in>0){
  532. $order=["order_type"=>'FKD',"order_code"=>$info['bk_code'],"order_id"=>$in, "order_status"=>0,"before_status"=>1];
  533. ProcessOrder::AddProcess($this->post['token'],$order);
  534. $ste = ["order_code"=>$info['bk_code'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  535. ActionLog::logAdd($this->post['token'],$ste,"FKD",0,$data);
  536. $temp=$info['status'];
  537. $info['status']=2;
  538. $info['wsm_code']=$wsm_code;
  539. $info['addtime']=date("Y-m-d H:i:s");
  540. $ood=Db::name('purchease')->save($info);
  541. if($ood){
  542. $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']];
  543. ProcessOrder::AddProcess($this->post['token'],$order);
  544. $ste = ["order_code"=>$info['bk_code'],"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
  545. ActionLog::logAdd($this->post['token'],$ste,"BHD",$info['status'],$info);
  546. Db::commit();
  547. return app_show(0,"新建成功");
  548. }
  549. }
  550. Db::rollback();
  551. return error_show(1005,"新建失败");
  552. }catch (\Exception $e){
  553. Db::rollback();
  554. return error_show(1005,"新建失败");
  555. }
  556. // return $in ? app_show(0,"新建成功"):error_show(1005,"新建失败");
  557. }
  558. public function delFeed(){
  559. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  560. if($id==""){
  561. return error_show(1001,'id不能为空');
  562. }
  563. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  564. if(empty($feed)){
  565. return error_show(1004,'未找到数据');
  566. }
  567. if($feed['status']==1){
  568. return error_show(1004,'反馈数据已采用无法删除');
  569. }
  570. $feed['is_del']= 1;
  571. $feed['updatetime']=date("Y-m-d H:i:s");
  572. $up = Db::name("purchease_feedback")->update($feed);
  573. if($up){
  574. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$feed['id'], "order_status"=>0];
  575. ProcessOrder::workdel($order);
  576. $ste = ["order_code"=>$feed['bk_code'],"status"=>$feed['status'],"action_remark"=>'',"action_type"=>"delete"];
  577. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$feed);
  578. }
  579. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  580. }
  581. public function infoFeed(){
  582. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  583. if($id==""){
  584. return error_show(1001,'id不能为空');
  585. }
  586. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  587. if(empty($info)){
  588. return error_show(1002,'未找到备库数据');
  589. }
  590. $feed = Db::name("purchease_feedback")->where(['bkcode'=>$info['bk_code'],'is_del'=>0])->find();
  591. if(empty($feed)){
  592. return error_show(1004,'未找到反馈数据');
  593. }
  594. $feed['wsm_name']="";
  595. if($feed['warehouse']!=""){
  596. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  597. ->where(["a.wsm_code"=>$feed['warehouse']])->field("a.name as wsm_name,b.name,b.code")->find();
  598. $feed['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  599. $feed['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  600. $feed['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  601. }
  602. if($feed['supplier']!=""){
  603. $supplie = Db::name("supplier")->where(['code'=>$feed['supplier'],"is_del"=>0])->find();//废弃
  604. $feed['supplier_name'] =isset($supplie['name']) ? $supplie['name']:"";
  605. }
  606. return app_show(0,"获取成功",$feed);
  607. }
  608. public function changeFeed(){
  609. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  610. if($id==""){
  611. return error_show(1001,'id不能为空');
  612. }
  613. $feed = Db::name("purchease")->where(['id'=>$id,'is_del'=>0])->find();
  614. if(empty($feed)){
  615. return error_show(1004,'未找到数据');
  616. }
  617. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']) : "";
  618. if($status==""){
  619. return error_show(1001,'参数status 不能为空');
  620. }
  621. $remark = isset($this->post['remark'])&& $this->post['remark']!=='' ? trim($this->post['remark']) : "";
  622. $userCommon= new \app\admin\common\User();
  623. $supplier_temp =$userCommon->handle("sInfo",["code"=>$feed['supplierNo']]);
  624. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"供应商不存在");
  625. $holder_id=$supplier_temp['data']['personid']??0;
  626. $holder_name=$supplier_temp['data']['person']??0;
  627. Db::startTrans();
  628. try{
  629. $tem =$feed['status'];
  630. $feed['remark']= $remark;
  631. $feed['status']= $status;
  632. $feed['updatetime']=date("Y-m-d H:i:s");
  633. $up = Db::name("purchease")->update($feed);
  634. if($up){
  635. if ($feed['status'] == 1) {
  636. // $supplier = Db::name('supplier')
  637. // ->field('id,person,personid')
  638. // ->where('code', $feed['supplierNo'])
  639. // ->findOrEmpty();
  640. $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];
  641. } 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']];
  642. ProcessOrder::AddProcess($this->post['token'], $order);
  643. $ste = ["order_code"=>$feed['bk_code'],"status"=>$tem,"action_remark"=>'',"action_type"=>"edit"];
  644. ActionLog::logAdd($this->post['token'],$ste,"BHD",$feed['status'],$feed);
  645. if($status==3){
  646. // $ware = Db::name("warehouse_addr")->where(["wsm_code"=>$feed['warehouse'],"is_del"=>0])->find();
  647. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  648. if(empty($purse)){
  649. Db::rollback();
  650. return error_show(1001,'未找到备库反馈数据');
  651. }
  652. $pe = $purse['status'];
  653. $purse['status']=1;
  654. $purse['addtime']=date("Y-m-d H:i:s");
  655. $up = Db::name("purchease_feedback")->save($purse);
  656. if($up==false){
  657. Db::rollback();
  658. return error_show(1001,'备库反馈数据状态修改失败');
  659. }
  660. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>$pe];
  661. ProcessOrder::AddProcess($this->post['token'],$order);
  662. $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"];
  663. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse);
  664. $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']])->find(); //废弃
  665. $inw = makeNo("CG");
  666. $goodinfo=Db::name('good_basic')
  667. ->field('id,createrid,creater')
  668. ->where(['is_del'=>0,'spuCode'=>$feed['spuCode']])
  669. ->findOrEmpty();
  670. $data=[
  671. "bkcode"=>$purse['bkcode'],
  672. 'cgdNo'=>$inw,
  673. "wsm_code"=>$purse['warehouse'],
  674. "good_code"=>$feed['good_code'],
  675. "good_name"=>$feed['good_name'],
  676. "good_type_code"=>$feed['good_type_code'],
  677. "good_num"=>$feed['good_num'],
  678. "send_num"=>0,
  679. "wsend_num"=>$feed['good_num'],
  680. 'good_price'=>$purse['good_price'],
  681. "total_fee"=>$purse['good_price'],
  682. 'pakge_fee'=>$purse['pakge_fee'],
  683. 'cert_fee'=>$purse['cert_fee'],
  684. 'open_fee'=>$purse['open_fee'],
  685. 'mark_fee'=>$purse['mark_fee'],
  686. 'teach_fee'=>$purse['teach_fee'],
  687. 'nake_fee'=>$purse['nake_fee'],
  688. 'demo_fee'=>$purse['demo_fee'],
  689. 'delivery_fee'=>$purse['delivery_fee'],
  690. 'weight'=>$purse['weight'],
  691. 'diff_weight'=>$purse['diff_weight'],
  692. 'diff_fee'=>$purse['diff_price'],
  693. 'cgder_id'=>$purse['purchaser_id'],
  694. 'cgder'=>$purse['purchaser'],
  695. "remark"=>$purse['remark'],
  696. "status"=>0,
  697. 'supplierNo'=>$purse['supplier'],
  698. 'supplier_name'=>isset($supplier['name']) ? $supplier['name']:"",
  699. 'lasttime'=>$purse['expecttime'],
  700. "addtime"=>date("Y-m-d H:i:s"),
  701. "updatetime"=>date("Y-m-d H:i:s"),
  702. 'good_createrid' => $goodinfo['createrid'],
  703. 'good_creater' => $goodinfo['creater'],//商品的创建人
  704. ];
  705. $in= Db::name("purchease_order")->insert($data,true);
  706. if($in>0){
  707. //当采购单是节点0待与供应商确认,推给供应商负责人
  708. if(!isset($supplier)) $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']]) //废弃
  709. ->find(); //废弃
  710. $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']];
  711. ProcessOrder::AddProcess($this->post['token'],$order);
  712. $ste = ["order_code"=>$inw,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"];
  713. ActionLog::logAdd($this->post['token'],$ste,"CGD",$data['status'],$data);
  714. //将采购单数据塞入到队列中
  715. $push_data = json_encode([
  716. 'supplierNo' => $data['supplierNo'],
  717. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  718. 'data' => [
  719. 'cgdNo' => $data['cgdNo'],
  720. 'spuCode' => $feed['spuCode'],
  721. 'good_name' => $data['good_name'],
  722. 'good_num' => $data['good_num'],
  723. 'good_price' => $data['good_price'],
  724. 'total_fee' => $data['total_fee'],
  725. 'weight' => $data['weight'],
  726. 'addtime' => $data['addtime'],
  727. ],
  728. ], JSON_UNESCAPED_UNICODE);
  729. // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  730. Db::commit();
  731. return app_show(0,"更新成功",['cgdNo'=>$inw]);
  732. }
  733. }else{
  734. if($status==4){
  735. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  736. if(empty($purse)){
  737. Db::rollback();
  738. return error_show(1001,'未找到备库反馈数据');
  739. }
  740. $pe=$purse['status'];
  741. $purse['status']=2;
  742. $purse['addtime']=date("Y-m-d H:i:s");
  743. $up = Db::name("purchease_feedback")->save($purse);
  744. if($up==false){
  745. Db::rollback();
  746. return error_show(1001,'备库反馈数据状态修改失败');
  747. }
  748. $order=["order_type"=>'FKD',"order_code"=>$feed['bk_code'],"order_id"=>$purse['id'],"order_status"=>$purse['status'],"before_status"=>1];
  749. ProcessOrder::AddProcess($this->post['token'],$order);
  750. $ste = ["order_code"=>$feed['bk_code'],"status"=>$pe,"action_remark"=>'',"action_type"=>"status"];
  751. ActionLog::logAdd($this->post['token'],$ste,"FKD",$feed['status'],$purse);
  752. }
  753. Db::commit();
  754. return app_show(0,"更新成功");
  755. }
  756. }
  757. Db::rollback();
  758. return error_show(1004,"更新失败");
  759. }catch (\Exception $e){
  760. Db::rollback();
  761. return error_show(1005,$e->getMessage());
  762. }
  763. }
  764. public function addwsm(){
  765. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  766. if($id==""){
  767. return error_show(1001,'id不能为空');
  768. }
  769. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  770. if($info==false){
  771. return error_show(1002,'未找到备库数据');
  772. }
  773. $wsm= isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']) : "";
  774. if($wsm==""){
  775. return error_show(1004,"参数wsm_code不能为空");
  776. }
  777. $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm,"is_del"=>0])->find();
  778. if($wsminfo==false){
  779. return error_show(1004,"未找到仓库数据");
  780. }
  781. $userCommon= new \app\admin\common\User();
  782. $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]);
  783. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"供应商不存在");
  784. $holder_id=$supplier_temp['data']['personid']??0;
  785. $holder_name=$supplier_temp['data']['person']??0;
  786. $info['wsm_code']=$wsm;
  787. $old_info_status = $info['status'];
  788. $info['status']=1;
  789. $info['updatetime']=date("y-m-d H;i:s");
  790. $up =Db::name("purchease")->save($info);
  791. if($up){
  792. //修改状态,添加待办
  793. ActionLog::logAdd($this->post['token'], [
  794. "order_code" => $info['bk_code'],//销售单code
  795. "status" => $old_info_status,//这里的status是之前的值
  796. "action_remark" => '',//备注
  797. "action_type" => "edit"//新建create,编辑edit,更改状态status
  798. ], "BHD", $info['status'], $info);
  799. // $supplier = Db::name('supplier')
  800. // ->field('id,person,personid')
  801. // ->where('code', $info['supplierNo'])
  802. // ->findOrEmpty();
  803. ProcessOrder::AddProcess($this->post['token'], [
  804. "order_type" => 'BHD',
  805. "order_code" => $info['bk_code'],//销售单code
  806. "order_id" => $info['id'],
  807. "order_status" => $info['status'],
  808. "before_status"=>$old_info_status,
  809. 'wait_id' => $holder_id,
  810. 'wait_name' => $holder_name,
  811. ]);
  812. return app_show(0,"备库单仓库选择成功");
  813. }else{
  814. return error_show(1004,"备库单仓库选择失败");
  815. }
  816. }
  817. //备库单生成采购单
  818. public function createCgd(){
  819. $bk_code=isset($this->post['bk_code'])&&$this->post['bk_code']!=="" ? trim($this->post['bk_code']):"";
  820. if($bk_code===""){
  821. return error_show(1004,"参数bk_code不能为空");
  822. }
  823. $info = Db::name("purchease")->where(["bk_code"=>$bk_code,"is_del"=>0])->find();
  824. if($info==false){
  825. return error_show(1002,'未找到备库数据');
  826. }
  827. $wsm_code =isset($this->post['wsm_code'])&&$this->post['wsm_code']!=="" ? trim($this->post['wsm_code']):'';
  828. if($wsm_code==""){
  829. return error_show(1002,'备库仓库不能为空');
  830. }
  831. $wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  832. if($wsminfo==false){
  833. return error_show(1002,'备库仓库未找到');
  834. }
  835. $good =Db::name("good_basic")->where([["spuCode","=",$info['spuCode']],["is_del","=",0]])->find();
  836. if($good==false){
  837. return error_show(1004,"未找到商品数据");
  838. }
  839. $userCommon= new \app\admin\common\User();
  840. $supplier_temp =$userCommon->handle("sInfo",["code"=>$info['supplierNo']]);
  841. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"未找到供应商数据");
  842. $supplierName=$supplier_temp['data']['name']??'';
  843. $personid=$supplier_temp['data']['personid']??'';
  844. $person=$supplier_temp['data']['person']??'';
  845. $goodnake =Db::name("good_nake")->where([["spuCode","=",$info['spuCode']],["is_del","=",0],["min_num","<=",
  846. $info['good_num']]])->order("min_num desc")->find();
  847. if($goodnake==false){
  848. return error_show(1004,"未找到成本数据");
  849. }
  850. $top_cat = made($good['cat_id']);
  851. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:"";
  852. if($good['is_gold_price']==1 && $top_cat_id==6){
  853. $gold = Db::name("gold_price1")->where(["type"=>$good['noble_metal'],"is_del"=>0,"status"=>1])->order("addtime desc")
  854. ->find();
  855. $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);
  856. $total_price = round($info['good_num']*$sale_price,2);
  857. }else{
  858. $sale_price = $goodnake['nake_total'];
  859. $total_price = round($info['good_num']*$sale_price,2);
  860. }
  861. $cgdCode = makeNo("CG");
  862. $cg =["cgdNo"=>$cgdCode,
  863. "bkcode"=>$bk_code,
  864. "wsm_code"=>$wsm_code,
  865. "cgder"=>$good['creater'],
  866. "cgder_id"=>$good['createrid'],
  867. "spuCode"=>$info['spuCode'],
  868. "good_name"=>$info['good_name'],
  869. "good_num"=>$info['good_num'],
  870. "good_price"=>$sale_price,
  871. "total_fee"=>$total_price,
  872. "pakge_fee"=>isset($goodnake['package_fee'])? $goodnake['package_fee']:0,
  873. "cert_fee"=>isset($goodnake['cert_fee'])? $goodnake['cert_fee']:0,
  874. "open_fee"=>$good['open_fee'],
  875. "delivery_fee"=>isset($goodnake['delivery_fee'])? $goodnake['delivery_fee']:0,
  876. "mark_fee"=>isset($goodnake['mark_fee'])? $goodnake['mark_fee']:0,
  877. "nake_fee"=>isset($goodnake['nake_fee'])? $goodnake['nake_fee']:0,
  878. "teach_fee"=>isset($goodnake['cost_fee'])? $goodnake['cost_fee']:0,
  879. "demo_fee"=>$good['demo_fee'],
  880. "diff_weight"=>"0",
  881. "diff_fee"=>"0",
  882. "gold_price"=>"0",
  883. "supplierNo"=>$info['supplierNo'],
  884. "supplier_name"=>$info['supplierName'],
  885. "companyNo"=>$info['companyNo'],
  886. "companyName"=>$info['companyName'],
  887. "send_status"=>1,
  888. "send_num"=>"0",
  889. "wsend_num"=>$info['good_num'],
  890. "weight"=>$good['noble_weight'],
  891. "remark"=>"",
  892. "status"=>0,//0表示初始化
  893. "lasttime"=>$info['lasttime'],
  894. "is_del"=>0,
  895. "order_type" => 1,//1备库
  896. "order_source" => 0,//0备库下单
  897. "good_type"=>1,
  898. "addtime"=>date("Y-m-d H:i:s"),
  899. "updatetime"=>date("Y-m-d H:i:s"),
  900. 'good_createrid' => $good['createrid'],
  901. 'good_creater' => $good['creater'],//商品创建人
  902. ];
  903. Db::startTrans();
  904. try{
  905. $up =Db::name("purchease_order")->insert($cg,true);
  906. if($up>0){
  907. $good = Db::name("good_stock")->where(["wsm_code" =>$wsm_code, "spuCode" => $info['spuCode'], "is_del" => 0])->find();
  908. if ($good == false) {
  909. $good = [
  910. "spuCode" => $info['spuCode'],
  911. "wsm_code" => $wsm_code,
  912. "usable_stock" => 0,
  913. "wait_out_stock" => 0,
  914. "wait_in_stock" => 0,
  915. "total_stock" => 0,
  916. "addtime" => date("Y-m-d H:i:s"),
  917. "updatetime" => date("Y-m-d H:i:s"),
  918. ];
  919. $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "create"];
  920. } else {
  921. $order = ["order_code" => $info['spuCode'], "status" => 1, "action_remark" => '', "action_type" => "edit"];
  922. }
  923. $good['wait_in_stock'] += $info['good_num'];
  924. $good['updatetime'] = date("Y-m-d H:i:s");
  925. $upd = Db::name("good_stock")->save($good);
  926. $good_data[] = ['good_log_code' => $cgdCode,"stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1,
  927. 'stock' => $info['good_num'], "stock_name" => "wait_in_stock"];
  928. if ($upd) {
  929. // 商品变动日志表,good_log_code字段存储采购单号
  930. $order = ["order_code" => $cgdCode, "status" => 0, "action_remark" => '', "action_type" => "create"];
  931. GoodLog::LogAdd($this->post['token'], $good_data, 'CGD');
  932. ActionLog::logAdd($this->post['token'], $order, "CGD", 0, $good);
  933. $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];
  934. ProcessOrder::AddProcess($this->post['token'], $process);
  935. $info['wsm_code'] = $wsm_code;
  936. $old_info_status = $info['status'];
  937. $info['status'] = 2;
  938. $info['updatetime'] = date("Y-m-d H:i:s");
  939. $bas = Db::name("purchease")->save($info);
  940. if ($bas) {
  941. //修改状态,添加待办
  942. ActionLog::logAdd($this->post['token'], [
  943. "order_code" => $info['bk_code'],//销售单code
  944. "status" => $old_info_status,//这里的status是之前的值
  945. "action_remark" => '',//备注
  946. "action_type" => "edit"//新建create,编辑edit,更改状态status
  947. ], "BHD", $info['status'], $info);
  948. ProcessOrder::AddProcess($this->post['token'], [
  949. "order_type" => 'BHD',
  950. "order_code" => $info['bk_code'],//销售单code
  951. "order_id" => $info['id'],
  952. "order_status" => $info['status'],
  953. "before_status"=> $old_info_status,
  954. 'holder_id' => $info['apply_id']
  955. ]);
  956. //维护台账记录
  957. Db::name('standing_book')->where('bk_code', $bk_code)->update([
  958. 'spuCode' => $cg['spuCode'],
  959. 'order_type' => $cg['order_type'],
  960. 'order_source' => $cg['order_source'],
  961. 'supplierNo' => $cg['supplierNo'],
  962. 'companyNo' => $cg['companyNo'],
  963. 'cgdNo' => $cg['cgdNo'],
  964. 'updatetime' => date('Y-m-d H:i:s'),
  965. ]);
  966. //将采购单数据塞入到队列中
  967. $push_data = json_encode([
  968. 'supplierNo' => $cg['supplierNo'],
  969. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  970. 'data' => [
  971. 'cgdNo' => $cg['cgdNo'],
  972. 'spuCode' => $cg['spuCode'],
  973. 'good_name' => $cg['good_name'],
  974. 'good_num' => $cg['good_num'],
  975. 'good_price' => $cg['good_price'],
  976. 'total_fee' => $cg['total_fee'],
  977. 'weight' => $cg['weight'],
  978. 'addtime' => $cg['addtime'],
  979. ],
  980. ], JSON_UNESCAPED_UNICODE);
  981. // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  982. Db::commit();
  983. return app_show(0, "采购单新建成功", ["cgdNo" => $cgdCode]);
  984. }
  985. }
  986. // }
  987. }
  988. Db::rollback();
  989. return error_show(1004,"采购单新建失败");
  990. }catch (\Exception $e){
  991. Db::rollback();
  992. return error_show(1004,$e->getMessage());
  993. }
  994. }
  995. }