Resign.php 34 KB

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