Resign.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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'] = $bkcode;
  32. }
  33. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code']):"";
  34. if($good_code!=""){
  35. $where['good_code'] = $good_code;
  36. }
  37. $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code']!="" ? trim($this->post['good_type_code']):"";
  38. if($good_type_code!=""){
  39. $where['good_type_code'] = $good_type_code;
  40. }
  41. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  42. if($wsm_code!=""){
  43. $where['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['good_name'] = Db::raw(" like %{$good_name}%");
  48. }
  49. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  50. if($apply_name!=""){
  51. $where['apply_name'] =Db::Raw("like '%{$apply_name}%'");
  52. }
  53. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  54. if($status!==""){
  55. $where['status'] = $status;
  56. }
  57. $count=Db::name("purchease")->where($where)->count();
  58. $total = ceil($count/$size);
  59. $page = $page >= $total ? $total : $page;
  60. $list = Db::name("purchease")->where($where)->page($page,$size)->select();
  61. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  62. }
  63. public function add(){
  64. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  65. if($token==""){
  66. return error_show(101,'token不能为空');
  67. }
  68. $good_code = isset($this->post['good_code'])&&$this->post['good_code']!="" ? trim($this->post['good_code']):"";
  69. if($good_code==""){
  70. return error_show(1002,'参数good_code 不能为空');
  71. }
  72. $good = Db::name("good")->where(['good_code'=>$good_code,'is_del'=>0])->find();
  73. if(empty($good)){
  74. return error_show(1002,'未找到商品数据');
  75. }
  76. $good_type_code = isset($this->post['good_type_code'])&&$this->post['good_type_code']!="" ? trim($this->post['good_type_code'])
  77. :"";
  78. if($good_type_code==""){
  79. return error_show(1002,'参数good_type_code 不能为空');
  80. }
  81. $good_type= Db::name("good_type")->where(['good_code'=>$good_code,'is_del'=>0,'type_code'=>$good_type_code])
  82. ->find();
  83. if(empty($good_type)){
  84. return error_show(1002,'未找到商品属性数据');
  85. }
  86. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=="" ? intval($this->post['good_num']) :"";
  87. if($good_num==''){
  88. return error_show(1002,'参数good_num 不能为空或零');
  89. }
  90. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  91. if($wsm_code==""){
  92. return error_show(1002,'参数wsm_code 不能为空');
  93. }
  94. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"is_del"=>0])->find();
  95. if(empty($wsminfo)){
  96. return error_show(1002,'未找到仓库数据');
  97. }
  98. $lastime = isset($this->post['lastime'])&&$this->post['lastime']!="" ? $this->post['lastime']:"";
  99. if($lastime==""){
  100. return error_show(1002,'参数lastime 不能为空');
  101. }
  102. $data = GetUserInfo($token);
  103. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  104. return error_show($data['code'],$data['message']);
  105. }
  106. $userinfo = $data['data'];
  107. $bk_code=makeNo("BK");
  108. $info = [
  109. "good_code"=>$good_code,
  110. "good_name"=>$good['good_name'],
  111. "good_num"=>$good_num,
  112. "good_type_code"=>$good_type_code,
  113. "wsm_code"=>$wsm_code,
  114. "lasttime"=>$lastime,
  115. "addtime"=>date("Y-m-d H:i:s"),
  116. "updatetime"=>date("Y-m-d H:i:s"),
  117. "apply_id"=>$userinfo['id'],
  118. "apply_name"=>$userinfo['nickname'],
  119. "bk_code"=>$bk_code
  120. ];
  121. $in = Db::name("purchease")->insert($info);
  122. return $in ? app_show(0,"新建成功",['bk_code'=>$bk_code]):error_show(1005,"新建失败");
  123. }
  124. public function info(){
  125. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  126. if($id==""){
  127. return error_show(1001,'id不能为空');
  128. }
  129. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  130. if(empty($info)){
  131. return error_show(1002,'未找到数据');
  132. }
  133. $info['wsm_name']="";
  134. if($info['wsm_code']!=""){
  135. $wsm = Db::name("warehouse_info")->where(['wsm_code'=>$info['wsm_code'],"is_del"=>0])->find();
  136. $info['wsm_name']=isset($wsm) &&$wsm['name']!=""?$wsm['name']:"";
  137. }
  138. return app_show(0,"获取成功",$info);
  139. }
  140. public function edit(){
  141. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  142. if($token==""){
  143. return error_show(101,'token不能为空');
  144. }
  145. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  146. if($id==""){
  147. return error_show(1001,'id不能为空');
  148. }
  149. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  150. if(empty($info)){
  151. return error_show(1002,'未找到数据');
  152. }
  153. $good_code = isset($this->post['good_code'])&&$this->post['good_code']!="" ? trim($this->post['good_code']):"";
  154. if($good_code==""){
  155. return error_show(1002,'参数good_code 不能为空');
  156. }
  157. $good = Db::name("good")->where(['good_code'=>$good_code,'is_del'=>0])->find();
  158. if(empty($good)){
  159. return error_show(1002,'未找到商品数据');
  160. }
  161. $good_type_code = isset($this->post['good_type_code'])&&$this->post['good_type_code']!="" ? trim($this->post['good_type_code'])
  162. :"";
  163. if($good_type_code==""){
  164. return error_show(1002,'参数good_type_code 不能为空');
  165. }
  166. $good_type= Db::name("good_type")->where(['good_code'=>$good_code,'is_del'=>0,'type_code'=>$good_type_code])
  167. ->find();
  168. if(empty($good_type)){
  169. return error_show(1002,'未找到商品属性数据');
  170. }
  171. $good_num = isset($this->post['good_num'])&&$this->post['good_num']!=="" ? intval($this->post['good_num']) :"";
  172. if($good_num==''){
  173. return error_show(1002,'参数good_num 不能为空或零');
  174. }
  175. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  176. if($wsm_code==""){
  177. return error_show(1002,'参数wsm_code 不能为空');
  178. }
  179. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"is_del"=>0])->find();
  180. if(empty($wsminfo)){
  181. return error_show(1002,'未找到仓库数据');
  182. }
  183. $lastime = isset($this->post['lastime'])&&$this->post['lastime']!="" ? $this->post['lastime']:"";
  184. if($lastime==""){
  185. return error_show(1002,'参数lastime 不能为空');
  186. }
  187. $data = GetUserInfo($token);
  188. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  189. return error_show($data['code'],$data['message']);
  190. }
  191. $userinfo = $data['data'];
  192. $up = [
  193. "good_code"=>$good_code,
  194. "good_name"=>$good['good_name'],
  195. "good_num"=>$good_num,
  196. "good_type_code"=>$good_type_code,
  197. "wsm_code"=>$wsm_code,
  198. "lasttime"=>$lastime,
  199. "updatetime"=>date("Y-m-d H:i:s"),
  200. "apply_id"=>$userinfo['id'],
  201. "apply_name"=>$userinfo['nickname']
  202. ];
  203. $in = Db::name("purchease")->where($info)->save($up);
  204. return $in ? app_show(0,"更新成功"):error_show(1005,"更新失败");
  205. }
  206. public function delete(){
  207. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  208. if($id==""){
  209. return error_show(1001,'id不能为空');
  210. }
  211. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  212. if(empty($info)){
  213. return error_show(1002,'未找到数据');
  214. }
  215. $info['is_del']=1;
  216. $info['updatetime']=date("Y-m-d H:i:s");
  217. $up = Db::name("purchease")->update($info);
  218. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  219. }
  220. public function status(){
  221. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  222. if($id==""){
  223. return error_show(1001,'id不能为空');
  224. }
  225. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  226. if(empty($info)){
  227. return error_show(1002,'未找到数据');
  228. }
  229. $status = isset($this->post['status'])&&$this->post['status']!=='' ? intval($this->post['status']) : "";
  230. if($status===""){
  231. return error_show(1001,'status不能为空');
  232. }
  233. $info['status']= $status;
  234. $info['updatetime']=date("Y-m-d H:i:s");
  235. $up = Db::name("purchease")->update($info);
  236. return $up ? app_show(0,"更新成功"):error_show(1005,"更新失败");
  237. }
  238. public function addFeed(){
  239. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  240. if($token==""){
  241. return error_show(101,'token不能为空');
  242. }
  243. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  244. if($id==""){
  245. return error_show(1001,'id不能为空');
  246. }
  247. $info = Db::name("purchease")->where(["id"=>$id,"is_del"=>0])->find();
  248. if(empty($info)){
  249. return error_show(1002,'未找到备库数据');
  250. }
  251. if($info['status']!=1){
  252. return error_show(1002,'备库数据状态有误');
  253. }
  254. $num = isset($this->post['num']) && $this->post['num']!=="" ? intval($this->post['num']):"";
  255. if($num==''){
  256. return error_show(1002,'参数num 不能为空或零');
  257. }
  258. $expecttime = isset($this->post['expecttime'])&&$this->post['expecttime']!=''?$this->post['expecttime'] :"";
  259. if($expecttime==''){
  260. return error_show(1002,'参数expecttime 不能为空');
  261. }
  262. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  263. if($wsm_code==""){
  264. return error_show(1002,'参数wsm_code 不能为空');
  265. }
  266. $wsminfo = Db::name("warehouse_info")->where(['wsm_code'=>$wsm_code,"is_del"=>0])->find();
  267. if(empty($wsminfo)){
  268. return error_show(1002,'未找到仓库数据');
  269. }
  270. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!="" ? trim($this->post['supplierNo']):"";
  271. if($supplierNo==""){
  272. return error_show(1002,'参数supplierNo 不能为空');
  273. }
  274. $supplie = Db::name("supplier")->where(['code'=>$supplierNo,"is_del"=>0])->find();
  275. if(empty($supplie)){
  276. return error_show(1002,'未找到供应商');
  277. }
  278. $good_price = isset($this->post['good_price'])&&$this->post['good_price']!=="" ? $this->post['good_price']:"";
  279. if($good_price===""){
  280. return error_show(1002,'参数good_price 不能为空');
  281. }
  282. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=="" ? $this->post['pakge_fee']:0;
  283. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=="" ? $this->post['cert_fee']:0;
  284. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=="" ? $this->post['open_fee']:0;
  285. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=="" ? $this->post['delivery_fee']:0;
  286. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=="" ? $this->post['mark_fee']:0;
  287. $teach_fee = isset($this->post['teach_fee'])&&$this->post['teach_fee']!=="" ? $this->post['teach_fee']:0;
  288. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!=="" ? $this->post['nake_fee']:0;
  289. $weight = isset($this->post['weight'])&&$this->post['weight']!=="" ? $this->post['weight']:0;
  290. $diff_weight =isset($this->post['diff_weight'])&&$this->post['diff_weight']!=="" ? $this->post['diff_weight']:0;
  291. $diff_price =isset($this->post['diff_price'])&&$this->post['diff_price']!=="" ? $this->post['diff_price']:0;
  292. $remark =isset($this->post['remark'])&&$this->post['remark']!=="" ? $this->post['remark']:'';
  293. $data = GetUserInfo($token);
  294. if((!empty($data) && $data['code']!=0) ||empty($data) ){
  295. return error_show($data['code'],$data['message']);
  296. }
  297. $userinfo = $data['data'];
  298. $data=[
  299. "bkcode"=>$info['bk_code'],
  300. "warehouse"=>$wsm_code,
  301. "num"=>$num,
  302. 'expecttime'=>$expecttime,
  303. 'supplier'=>isset($supplie) && $supplie['name']!=''? $supplie['name']:'',
  304. 'good_price'=>$good_price,
  305. 'pakge_fee'=>$pakge_fee,
  306. 'cert_fee'=>$cert_fee,
  307. 'open_fee'=>$open_fee,
  308. 'mark_fee'=>$mark_fee,
  309. 'teach_fee'=>$teach_fee,
  310. 'nake_fee'=>$nake_fee,
  311. 'delivery_fee'=>$delivery_fee,
  312. 'weight'=>$weight,
  313. 'remark'=>$remark,
  314. 'diff_weight'=>$diff_weight,
  315. 'diff_price'=>$diff_price,
  316. 'purchaser'=>$userinfo['nickname'],
  317. 'purchaser_id'=>$userinfo['id'],
  318. "addtime"=>date("Y-m-d H:i:s"),
  319. "updatetime"=>date("Y-m-d H:i:s")
  320. ];
  321. $in = Db::name('purchease_feedback')->insert($data);
  322. return $in ? app_show(0,"新建成功"):error_show(1005,"新建失败");
  323. }
  324. public function delFeed(){
  325. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  326. if($id==""){
  327. return error_show(1001,'id不能为空');
  328. }
  329. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  330. if(empty($feed)){
  331. return error_show(1004,'未找到数据');
  332. }
  333. if($feed['status']==1){
  334. return error_show(1004,'反馈数据已采用无法删除');
  335. }
  336. $feed['is_del']= 1;
  337. $feed['updatetime']=date("Y-m-d H:i:s");
  338. $up = Db::name("purchease_feedback")->update($feed);
  339. return $up ? app_show(0,"删除成功"):error_show(1005,"删除失败");
  340. }
  341. public function infoFeed(){
  342. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  343. if($id==""){
  344. return error_show(1001,'id不能为空');
  345. }
  346. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  347. if(empty($feed)){
  348. return error_show(1004,'未找到数据');
  349. }
  350. $feed['wsm_name']="";
  351. if($feed['warehouse']!=""){
  352. $wsm = Db::name("warehouse_info")->where(['wsm_code'=>$feed['warehouse'],"is_del"=>0])->find();
  353. $feed['wsm_name']=isset($wsm) &&$wsm['name']!=""?$wsm['name']:"";
  354. }
  355. return app_show(0,"获取成功",$feed);
  356. }
  357. public function changeFeed(){
  358. $id = isset($this->post['id']) ? intval($this->post['id']) : "";
  359. if($id==""){
  360. return error_show(1001,'id不能为空');
  361. }
  362. $feed = Db::name("purchease_feedback")->where(['id'=>$id,'is_del'=>0])->find();
  363. if(empty($feed)){
  364. return error_show(1004,'未找到数据');
  365. }
  366. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']) : "";
  367. if($status==""){
  368. return error_show(1001,'参数status 不能为空');
  369. }
  370. $remark = isset($this->post['remark'])&& $this->post['remark']!=='' ? trim($this->post['remark']) : "";
  371. Db::startTrans();
  372. try{
  373. $feed['remark']= $remark;
  374. $feed['status']= $status;
  375. $feed['updatetime']=date("Y-m-d H:i:s");
  376. $up = Db::name("purchease_feedback")->update($feed);
  377. if($up){
  378. if($status==1){
  379. // $ware = Db::name("warehouse_addr")->where(["wsm_code"=>$feed['warehouse'],"is_del"=>0])->find();
  380. $purse = Db::name("purchease")->where(['bk_code'=>$feed['bkcode'],"is_del"=>0])->find();
  381. if(empty($purse)){
  382. Db::rollback();
  383. return error_show(1001,'未找到备库申请数据');
  384. }
  385. $supplier = Db::name("supplier")->where(["code"=>$feed['supplier']])->find();
  386. $inw = makeNo("CG");
  387. $data=[
  388. "bkcode"=>$feed['bkcode'],
  389. 'cgdNo'=>$inw,
  390. "wsm_code"=>$feed['warehouse'],
  391. "good_code"=>$purse['good_code'],
  392. "good_name"=>$purse['good_name'],
  393. "good_type_code"=>$purse['good_type_code'],
  394. "good_num"=>$purse['good_num'],
  395. "send_num"=>0,
  396. "wsend_num"=>$purse['good_num'],
  397. 'good_price'=>$feed['good_price'],
  398. "total_fee"=>$feed['good_price'],
  399. 'pakge_fee'=>$feed['pakge_fee'],
  400. 'cert_fee'=>$feed['cert_fee'],
  401. 'open_fee'=>$feed['open_fee'],
  402. 'mark_fee'=>$feed['mark_fee'],
  403. 'teach_fee'=>$feed['teach_fee'],
  404. 'nake_fee'=>$feed['nake_fee'],
  405. 'delivery_fee'=>$feed['delivery_fee'],
  406. 'weight'=>$feed['weight'],
  407. 'diff_weight'=>$feed['diff_weight'],
  408. 'diff_price'=>$feed['diff_price'],
  409. 'cgder_id'=>$feed['purchaser_id'],
  410. 'cgder'=>$feed['purchaser'],
  411. 'supplierNo'=>$feed['supplier'],
  412. 'supplier_name'=>isset($supplier['name']) ? $supplier['name']:"",
  413. 'lasttime'=>$feed['expecttime'],
  414. "addtime"=>date("Y-m-d H:i:s"),
  415. "updatetime"=>date("Y-m-d H:i:s")
  416. ];
  417. $in= Db::name("purchease_order")->insert($data);
  418. if($in){
  419. Db::commit();
  420. return app_show(0,"更新成功",['cgdNo'=>$inw]);
  421. }
  422. }else{
  423. Db::commit();
  424. return app_show(0,"更新成功");
  425. }
  426. }
  427. Db::rollback();
  428. return error_show(1004,"更新失败");
  429. }catch (\Exception $e){
  430. Db::rollback();
  431. return error_show(1005,$e->getMessage());
  432. }
  433. }
  434. }