Resign.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <?php
  2. /**
  3. * 备库申请
  4. */
  5. namespace app\admin\controller;
  6. use app\BaseController;
  7. use think\facade\Db;
  8. use think\App;
  9. class Resign extends BaseController
  10. {
  11. public $post="";
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->post = $this->request->post();
  16. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  17. // if($token==""){
  18. // return error_show(101,'token不能为空');
  19. // }
  20. // $effetc = VerifyTokens($token);
  21. // if(!empty($effetc) && $effetc['code']!=0) {
  22. // return error_show($effetc['code'], $effetc['message']);
  23. // }
  24. }
  25. public function list(){
  26. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  27. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  28. $where =[['is_del',"=",0]];
  29. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  30. if($bkcode!=""){
  31. //$where['bk_code'] = $bk_code;
  32. $where[]=['bk_code',"like","%{$bkcode}%"];
  33. }
  34. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']):"";
  35. if($good_code!=""){
  36. // $where['good_code'] = $good_code;
  37. $where[]=['good_code',"like","%{$good_code}%"];
  38. }
  39. $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code']!="" ? trim($this->post['good_type_code']):"";
  40. if($good_type_code!=""){
  41. // $where['good_type_code'] = $good_type_code;
  42. $where[]=['good_type_code',"like","%{$good_type_code}%"];
  43. }
  44. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  45. if($wsm_code!=""){
  46. //$where['wsm_code'] = $wsm_code;
  47. $where[]=['wsm_code',"=",$wsm_code];
  48. }
  49. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  50. if($good_name!=""){
  51. // $where['good_name'] = Db::raw(" like '%{$good_name}%'");
  52. $where[]=['good_name',"like","%{$good_name}%"];
  53. }
  54. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  55. if($apply_name!=""){
  56. // $where['apply_name'] =Db::Raw("like '%{$apply_name}%'");
  57. $where[]=['apply_name',"like","%{$apply_name}%"];
  58. }
  59. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  60. if($status!==""){
  61. // $where['status'] = $status;
  62. $where[]=['status',"=",$status];
  63. }
  64. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  65. if($start!==""){
  66. //$where['addtime'] = Db::Raw(">= '{$start}'");
  67. $where[]=['addtime',">=",$start];
  68. }
  69. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  70. if($end!==""){
  71. // $where['addtime'] = Db::Raw("<= '{$end}'");
  72. $where[]=['addtime',"<=",$end];
  73. }
  74. $count=Db::name("purchease")->where($where)->count();
  75. $total = ceil($count/$size);
  76. $page = $page >= $total ? $total : $page;
  77. $list = Db::name("purchease")->where($where)->page($page,$size)->order("addtime desc")->select();
  78. $data=[];
  79. foreach ($list as $value){
  80. $value['wsm_name']="";
  81. $value['wsm_supplier']="";
  82. $value['wsm_supplierNo']="";
  83. if($value['wsm_code']!=""){
  84. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  85. ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  86. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  87. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  88. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  89. }
  90. $data[]=$value;
  91. }
  92. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  93. }
  94. public function add(){
  95. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  96. if($token==""){
  97. return error_show(101,'token不能为空');
  98. }
  99. $good_code = isset($this->post['good_code'])&&$this->post['good_code']!="" ? trim($this->post['good_code']):"";
  100. if($good_code==""){
  101. return error_show(1002,'参数good_code 不能为空');
  102. }
  103. $good = Db::name("good")->where(['good_code'=>$good_code,'is_del'=>0])->find();
  104. if(empty($good)){
  105. return error_show(1002,'未找到商品数据');
  106. }
  107. $good_type_code = isset($this->post['good_type_code'])&&$this->post['good_type_code']!="" ? trim($this->post['good_type_code'])
  108. :"";
  109. if($good_type_code!==""){
  110. $good_type= Db::name("good_type")->where(['good_code'=>$good_code,'is_del'=>0,'type_code'=>$good_type_code])
  111. ->find();
  112. if(empty($good_type)){
  113. return error_show(1002,'未找到商品属性数据');
  114. }
  115. }
  116. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=="" ? intval($this->post['good_num']) :"";
  117. if($good_num==''){
  118. return error_show(1002,'参数good_num 不能为空或零');
  119. }
  120. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  121. if($wsm_code==""){
  122. return error_show(1002,'参数wsm_code 不能为空');
  123. }
  124. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"is_del"=>0])->find();
  125. if(empty($wsminfo)){
  126. return error_show(1002,'未找到仓库数据');
  127. }
  128. $lastime = isset($this->post['lastime'])&&$this->post['lastime']!="" ? $this->post['lastime']:"";
  129. if($lastime==""){
  130. return error_show(1002,'参数lastime 不能为空');
  131. }
  132. $data = GetUserInfo($token);
  133. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  134. return error_show($data['code'],$data['message']);
  135. }
  136. $userinfo = $data['data'];
  137. $bk_code=makeNo("BK");
  138. $info = [
  139. "good_code"=>$good_code,
  140. "good_name"=>$good['good_name'],
  141. "good_num"=>$good_num,
  142. "good_type_code"=>$good_type_code,
  143. "wsm_code"=>$wsm_code,
  144. "lasttime"=>$lastime,
  145. "addtime"=>date("Y-m-d H:i:s"),
  146. "updatetime"=>date("Y-m-d H:i:s"),
  147. "apply_id"=>$userinfo['id'],
  148. "apply_name"=>$userinfo['nickname'],
  149. "bk_code"=>$bk_code
  150. ];
  151. $in = Db::name("purchease")->insert($info);
  152. return $in ? app_show(0,"新建成功",['bk_code'=>$bk_code]):error_show(1005,"新建失败");
  153. }
  154. /**
  155. * @return \think\response\Json|void
  156. * @throws \think\db\exception\DataNotFoundException
  157. * @throws \think\db\exception\DbException
  158. * @throws \think\db\exception\ModelNotFoundException
  159. */
  160. public function copy(){
  161. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  162. if($id==""){
  163. return error_show(1001,'id不能为空');
  164. }
  165. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  166. if(empty($info)){
  167. return error_show(1002,'未找到数据');
  168. }
  169. $data = GetUserInfo($this->post['token']);
  170. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  171. return error_show($data['code'],$data['message']);
  172. }
  173. $userinfo = $data['data'];
  174. $bk_code=makeNo("BK");
  175. $info['bk_code']=$bk_code;
  176. $info['status']=0;
  177. $info['addtime']=date("Y-m-d H:i:s");
  178. $info['updatetime']=date("Y-m-d H:i:s");
  179. $info['apply_id']=$userinfo['id'];
  180. $info['apply_name']=$userinfo['nickname'];
  181. unset($info['id']);
  182. $in = Db::name("purchease")->insert($info);
  183. return $in ? app_show(0,"新建成功",['bk_code'=>$bk_code]):error_show(1005,"新建失败");
  184. }
  185. /**
  186. * @return \think\response\Json|void
  187. * @throws \think\db\exception\DataNotFoundException
  188. * @throws \think\db\exception\DbException
  189. * @throws \think\db\exception\ModelNotFoundException
  190. */
  191. public function info(){
  192. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  193. if($id==""){
  194. return error_show(1001,'id不能为空');
  195. }
  196. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  197. if(empty($info)){
  198. return error_show(1002,'未找到数据');
  199. }
  200. $info['wsm_name']="";
  201. if($info['wsm_code']!=""){
  202. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  203. ->where(["a.wsm_code"=>$info['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  204. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  205. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  206. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  207. }
  208. $feed = Db::name("purchease_feedback")->where(['bkcode'=>$info['bk_code'],'is_del'=>0])->find();
  209. $info['feedback'] = [];
  210. if(!empty($feed)){
  211. $feed['wsm_name']="";
  212. if($feed['warehouse']!=""){
  213. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  214. ->where(["a.wsm_code"=>$feed['warehouse']])->field("a.name as wsm_name,b.name,b.code")->find();
  215. $feed['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  216. $feed['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  217. $feed['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  218. }
  219. if($feed['supplier']!=""){
  220. $supplie = Db::name("supplier")->where(['code'=>$feed['supplier'],"is_del"=>0])->find();
  221. $feed['supplier_name'] =isset($supplie['name']) ? $supplie['name']:"";
  222. }
  223. $info['feedback'] = $feed;
  224. }
  225. return app_show(0,"获取成功",$info);
  226. }
  227. public function edit(){
  228. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  229. if($token==""){
  230. return error_show(101,'token不能为空');
  231. }
  232. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  233. if($id==""){
  234. return error_show(1001,'id不能为空');
  235. }
  236. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  237. if(empty($info)){
  238. return error_show(1002,'未找到数据');
  239. }
  240. $good_code = isset($this->post['good_code'])&&$this->post['good_code']!="" ? trim($this->post['good_code']):"";
  241. if($good_code==""){
  242. return error_show(1002,'参数good_code 不能为空');
  243. }
  244. $good = Db::name("good")->where(['good_code'=>$good_code,'is_del'=>0])->find();
  245. if(empty($good)){
  246. return error_show(1002,'未找到商品数据');
  247. }
  248. $good_type_code = isset($this->post['good_type_code'])&&$this->post['good_type_code']!="" ? trim($this->post['good_type_code'])
  249. :"";
  250. if($good_type_code!=''){
  251. $good_type= Db::name("good_type")->where(['good_code'=>$good_code,'is_del'=>0,'type_code'=>$good_type_code])
  252. ->find();
  253. if(empty($good_type)){
  254. return error_show(1002,'未找到商品属性数据');
  255. }
  256. }
  257. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=="" ? intval($this->post['good_num']) :"";
  258. if($good_num==''){
  259. return error_show(1002,'参数good_num 不能为空或零');
  260. }
  261. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  262. if($wsm_code==""){
  263. return error_show(1002,'参数wsm_code 不能为空');
  264. }
  265. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"is_del"=>0])->find();
  266. if(empty($wsminfo)){
  267. return error_show(1002,'未找到仓库数据');
  268. }
  269. $lastime = isset($this->post['lastime'])&&$this->post['lastime']!="" ? $this->post['lastime']:"";
  270. if($lastime==""){
  271. return error_show(1002,'参数lastime 不能为空');
  272. }
  273. $data = GetUserInfo($token);
  274. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  275. return error_show($data['code'],$data['message']);
  276. }
  277. $userinfo = $data['data'];
  278. $up = [
  279. "good_code"=>$good_code,
  280. "good_name"=>$good['good_name'],
  281. "good_num"=>$good_num,
  282. "good_type_code"=>$good_type_code,
  283. "wsm_code"=>$wsm_code,
  284. "lasttime"=>$lastime,
  285. "updatetime"=>date("Y-m-d H:i:s"),
  286. "apply_id"=>$userinfo['id'],
  287. "apply_name"=>$userinfo['nickname']
  288. ];
  289. $in = Db::name("purchease")->where($info)->save($up);
  290. return $in ? app_show(0,"更新成功"):error_show(1005,"更新失败");
  291. }
  292. public function delete(){
  293. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  294. if($id==""){
  295. return error_show(1001,'id不能为空');
  296. }
  297. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  298. if(empty($info)){
  299. return error_show(1002,'未找到数据');
  300. }
  301. $info['is_del']=1;
  302. $info['updatetime']=date("Y-m-d H:i:s");
  303. $up = Db::name("purchease")->update($info);
  304. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  305. }
  306. public function status(){
  307. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  308. if($id==""){
  309. return error_show(1001,'id不能为空');
  310. }
  311. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  312. if(empty($info)){
  313. return error_show(1002,'未找到数据');
  314. }
  315. $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
  316. if($status===""){
  317. return error_show(1001,'status不能为空');
  318. }
  319. $info['status']= $status;
  320. $info['updatetime']=date("Y-m-d H:i:s");
  321. $up = Db::name("purchease")->update($info);
  322. return $up ? app_show(0,"更新成功"):error_show(1005,"更新失败");
  323. }
  324. public function addFeed(){
  325. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  326. if($token==""){
  327. return error_show(101,'token不能为空');
  328. }
  329. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  330. if($id==""){
  331. return error_show(1001,'id不能为空');
  332. }
  333. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  334. if(empty($info)){
  335. return error_show(1002,'未找到备库数据');
  336. }
  337. if($info['status']!=1){
  338. return error_show(1002,'备库数据状态有误');
  339. }
  340. $num = isset($this->post['num']) && $this->post['num']!=="" ? intval($this->post['num']):"";
  341. if($num==''){
  342. return error_show(1002,'参数num 不能为空或零');
  343. }
  344. $expecttime = isset($this->post['expecttime'])&&$this->post['expecttime']!=''?$this->post['expecttime'] :"";
  345. if($expecttime==''){
  346. return error_show(1002,'参数expecttime 不能为空');
  347. }
  348. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  349. if($wsm_code==""){
  350. return error_show(1002,'参数wsm_code 不能为空');
  351. }
  352. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"is_del"=>0])->find();
  353. if(empty($wsminfo)){
  354. return error_show(1002,'未找到仓库数据');
  355. }
  356. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!="" ? trim($this->post['supplierNo']):"";
  357. if($supplierNo==""){
  358. return error_show(1002,'参数supplierNo 不能为空');
  359. }
  360. $supplie = Db::name("supplier")->where(['code'=>$supplierNo,"is_del"=>0])->find();
  361. if(empty($supplie)){
  362. return error_show(1002,'未找到供应商');
  363. }
  364. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=="" ? $this->post['good_price']:"";
  365. if($good_price===""){
  366. return error_show(1002,'参数good_price 不能为空');
  367. }
  368. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=="" ? $this->post['pakge_fee']:0;
  369. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=="" ? $this->post['cert_fee']:0;
  370. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=="" ? $this->post['open_fee']:0;
  371. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=="" ? $this->post['delivery_fee']:0;
  372. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=="" ? $this->post['mark_fee']:0;
  373. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=="" ? $this->post['teach_fee']:0;
  374. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=="" ? $this->post['nake_fee']:0;
  375. $weight = isset($this->post['weight'])&&$this->post['weight']!=="" ? $this->post['weight']:0;
  376. $diff_weight =isset($this->post['diff_weight'])&&$this->post['diff_weight']!=="" ? $this->post['diff_weight']:0;
  377. $diff_price =isset($this->post['diff_price'])&&$this->post['diff_price']!=="" ? $this->post['diff_price']:0;
  378. $remark =isset($this->post['remark'])&&$this->post['remark']!=="" ? $this->post['remark']:'';
  379. $data = GetUserInfo($token);
  380. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  381. return error_show($data['code'],$data['message']);
  382. }
  383. $userinfo = $data['data'];
  384. $data=[
  385. "bkcode"=>$info['bk_code'],
  386. "warehouse"=>$wsm_code,
  387. "num"=>$num,
  388. 'expecttime'=>$expecttime,
  389. 'supplier'=>isset($supplie) && $supplie['code']!=''? $supplie['code']:'',
  390. 'good_price'=>$good_price,
  391. 'pakge_fee'=>$pakge_fee,
  392. 'cert_fee'=>$cert_fee,
  393. 'open_fee'=>$open_fee,
  394. 'mark_fee'=>$mark_fee,
  395. 'teach_fee'=>$teach_fee,
  396. 'nake_fee'=>$nake_fee,
  397. 'delivery_fee'=>$delivery_fee,
  398. 'weight'=>$weight,
  399. 'remark'=>$remark,
  400. 'diff_weight'=>$diff_weight,
  401. 'diff_price'=>$diff_price,
  402. 'purchaser'=>$userinfo['nickname'],
  403. 'purchaser_id'=>$userinfo['id'],
  404. "addtime"=>date("Y-m-d H:i:s"),
  405. "updatetime"=>date("Y-m-d H:i:s")
  406. ];
  407. Db::startTrans();
  408. try{
  409. $in = Db::name('purchease_feedback')->insert($data);
  410. if($in){
  411. $info['status']=2;
  412. $info['addtime']=date("Y-m-d H:i:s");
  413. $ood=Db::name('purchease')->save($info);
  414. if($ood){
  415. Db::commit();
  416. return app_show(0,"新建成功");
  417. }
  418. }
  419. Db::rollback();
  420. return error_show(1005,"新建失败");
  421. }catch (\Exception $e){
  422. Db::rollback();
  423. return error_show(1005,"新建失败");
  424. }
  425. // return $in ? app_show(0,"新建成功"):error_show(1005,"新建失败");
  426. }
  427. public function delFeed(){
  428. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  429. if($id==""){
  430. return error_show(1001,'id不能为空');
  431. }
  432. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  433. if(empty($feed)){
  434. return error_show(1004,'未找到数据');
  435. }
  436. if($feed['status']==1){
  437. return error_show(1004,'反馈数据已采用无法删除');
  438. }
  439. $feed['is_del']= 1;
  440. $feed['updatetime']=date("Y-m-d H:i:s");
  441. $up = Db::name("purchease_feedback")->update($feed);
  442. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  443. }
  444. public function infoFeed(){
  445. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  446. if($id==""){
  447. return error_show(1001,'id不能为空');
  448. }
  449. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  450. if(empty($info)){
  451. return error_show(1002,'未找到备库数据');
  452. }
  453. $feed = Db::name("purchease_feedback")->where(['bkcode'=>$info['bk_code'],'is_del'=>0])->find();
  454. if(empty($feed)){
  455. return error_show(1004,'未找到反馈数据');
  456. }
  457. $feed['wsm_name']="";
  458. if($feed['warehouse']!=""){
  459. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  460. ->where(["a.wsm_code"=>$feed['warehouse']])->field("a.name as wsm_name,b.name,b.code")->find();
  461. $feed['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  462. $feed['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  463. $feed['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  464. }
  465. if($feed['supplier']!=""){
  466. $supplie = Db::name("supplier")->where(['code'=>$feed['supplier'],"is_del"=>0])->find();
  467. $feed['supplier_name'] =isset($supplie['name']) ? $supplie['name']:"";
  468. }
  469. return app_show(0,"获取成功",$feed);
  470. }
  471. public function changeFeed(){
  472. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  473. if($id==""){
  474. return error_show(1001,'id不能为空');
  475. }
  476. $feed = Db::name("purchease")->where(['id'=>$id,'is_del'=>0])->find();
  477. if(empty($feed)){
  478. return error_show(1004,'未找到数据');
  479. }
  480. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']) : "";
  481. if($status==""){
  482. return error_show(1001,'参数status 不能为空');
  483. }
  484. $remark = isset($this->post['remark'])&& $this->post['remark']!=='' ? trim($this->post['remark']) : "";
  485. Db::startTrans();
  486. try{
  487. $feed['remark']= $remark;
  488. $feed['status']= $status;
  489. $feed['updatetime']=date("Y-m-d H:i:s");
  490. $up = Db::name("purchease")->update($feed);
  491. if($up){
  492. if($status==3){
  493. // $ware = Db::name("warehouse_addr")->where(["wsm_code"=>$feed['warehouse'],"is_del"=>0])->find();
  494. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  495. if(empty($purse)){
  496. Db::rollback();
  497. return error_show(1001,'未找到备库反馈数据');
  498. }
  499. $purse['status']=1;
  500. $purse['addtime']=date("Y-m-d H:i:s");
  501. $up = Db::name("purchease_feedback")->save($purse);
  502. if($up==false){
  503. Db::rollback();
  504. return error_show(1001,'备库反馈数据状态修改失败');
  505. }
  506. $supplier = Db::name("supplier")->where(["code"=>$purse['supplier']])->find();
  507. $inw = makeNo("CG");
  508. $data=[
  509. "bkcode"=>$purse['bkcode'],
  510. 'cgdNo'=>$inw,
  511. "wsm_code"=>$purse['warehouse'],
  512. "good_code"=>$feed['good_code'],
  513. "good_name"=>$feed['good_name'],
  514. "good_type_code"=>$feed['good_type_code'],
  515. "good_num"=>$feed['good_num'],
  516. "send_num"=>0,
  517. "wsend_num"=>$feed['good_num'],
  518. 'good_price'=>$purse['good_price'],
  519. "total_fee"=>$purse['good_price'],
  520. 'pakge_fee'=>$purse['pakge_fee'],
  521. 'cert_fee'=>$purse['cert_fee'],
  522. 'open_fee'=>$purse['open_fee'],
  523. 'mark_fee'=>$purse['mark_fee'],
  524. 'teach_fee'=>$purse['teach_fee'],
  525. 'nake_fee'=>$purse['nake_fee'],
  526. 'delivery_fee'=>$purse['delivery_fee'],
  527. 'weight'=>$purse['weight'],
  528. 'diff_weight'=>$purse['diff_weight'],
  529. 'diff_fee'=>$purse['diff_price'],
  530. 'cgder_id'=>$purse['purchaser_id'],
  531. 'cgder'=>$purse['purchaser'],
  532. "remark"=>$purse['remark'],
  533. "status"=>0,
  534. 'supplierNo'=>$purse['supplier'],
  535. 'supplier_name'=>isset($supplier['name']) ? $supplier['name']:"",
  536. 'lasttime'=>$purse['expecttime'],
  537. "addtime"=>date("Y-m-d H:i:s"),
  538. "updatetime"=>date("Y-m-d H:i:s")
  539. ];
  540. $in= Db::name("purchease_order")->insert($data);
  541. if($in){
  542. Db::commit();
  543. return app_show(0,"更新成功",['cgdNo'=>$inw]);
  544. }
  545. }else{
  546. if($status==4){
  547. $purse = Db::name("purchease_feedback")->where(['bkcode'=>$feed['bk_code'],"is_del"=>0])->find();
  548. if(empty($purse)){
  549. Db::rollback();
  550. return error_show(1001,'未找到备库反馈数据');
  551. }
  552. $purse['status']=2;
  553. $purse['addtime']=date("Y-m-d H:i:s");
  554. $up = Db::name("purchease_feedback")->save($purse);
  555. if($up==false){
  556. Db::rollback();
  557. return error_show(1001,'备库反馈数据状态修改失败');
  558. }
  559. }
  560. Db::commit();
  561. return app_show(0,"更新成功");
  562. }
  563. }
  564. Db::rollback();
  565. return error_show(1004,"更新失败");
  566. }catch (\Exception $e){
  567. Db::rollback();
  568. return error_show(1005,$e->getMessage());
  569. }
  570. }
  571. }