Resign.php 52 KB

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