Resign.php 33 KB

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