Suppler.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\Ocr;
  4. use app\admin\model\ChangeLog;
  5. use app\BaseController;
  6. use think\App;
  7. use think\facade\Db;
  8. //供应商
  9. class Suppler extends BaseController
  10. {
  11. public $post = "";
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->post=$this->request->post();
  16. }
  17. public function create(){
  18. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  19. if($name==""){
  20. return error_show(1002,"参数name不能为空");
  21. }
  22. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  23. if (!empty($rename)) {
  24. return error_show(1002, "公司名称已存在");
  25. }
  26. $tr=makeNo("QS");
  27. $source= isset($this->post['source']) && $this->post['source']!==""? intval($this->post['source']) :"";
  28. if($source===""){
  29. return error_show(1002,"供应商来源不能为空");
  30. }
  31. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  32. if($token==''){
  33. return error_show(105,"参数token不能为空");
  34. }
  35. $user =GetUserInfo($token);
  36. if(empty($user)||$user['code']!=0){
  37. return error_show(1002,"创建人数据不存在");
  38. }
  39. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  40. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  41. $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
  42. if($personid==""){
  43. return error_show(1002,"参数personid不能为空");
  44. }
  45. $to= GetInfoById($token,['id'=>$personid]);
  46. if(empty($to)||$to['code']!=0){
  47. return app_show(1002,"负责人信息不存在");
  48. }
  49. $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
  50. $type = isset($this->post['type']) && $this->post['type']!==""? intval($this->post['type']) :"";
  51. if($type===""){
  52. return error_show(1002,"申请类型不能为空");
  53. }
  54. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? intval($this->post['coop_state']):"";
  55. if($coop_state===""){
  56. return error_show(1002,"参数coop_state不能为空");
  57. }
  58. $category = isset($this->post['category']) && $this->post['category'] !==""? intval($this->post['category']):"";
  59. if($category===""){
  60. return error_show(1002,"参数category不能为空");
  61. }
  62. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? intval($this->post['delivery_way']):"";
  63. if($delivery_way===""){
  64. return error_show(1002,"参数delivery_way不能为空");
  65. }
  66. $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
  67. if($level===""){
  68. return error_show(1002,"参数level不能为空");
  69. }
  70. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? intval($this->post['supplier_type']):"";
  71. if($supplier_type===""){
  72. return error_show(1002,"参数supplier_type不能为空");
  73. }
  74. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? intval($this->post['pay_type']):"";
  75. if($pay_type===""){
  76. return error_show(1002,"参数pay_type不能为空");
  77. }
  78. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  79. // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  80. // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  81. $nature = isset($this->post['nature']) && $this->post['nature']!==""? intval($this->post['nature']) :"";
  82. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  83. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? intval($this->post['ticket_type']) :"";
  84. $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  85. $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  86. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  87. $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  88. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  89. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  90. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  91. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  92. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  93. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  94. $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  95. // $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"1";
  96. //$registertime= isset($this->post['registertime']) && $this->post['registertime']!==""?
  97. // $this->post['registertime'] :"";
  98. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  99. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  100. if($contactor==""){
  101. return error_show(1002,"参数contactor不能为空");
  102. }
  103. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  104. if($mobile==""){
  105. return error_show(1002,"参数mobile不能为空");
  106. }
  107. $telephone = isset($this->post['telephone']) && $this->post['telephone'] !=="" ? trim($this->post['telephone']):"";
  108. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  109. if($position==""){
  110. return error_show(1002,"参数position不能为空");
  111. }
  112. Db::startTrans();
  113. try{
  114. $data=[
  115. "name"=>$name,
  116. "source"=>$source,
  117. "coop_state"=>$coop_state,
  118. "category"=>$category,
  119. "delivery_way"=>$delivery_way,
  120. "level"=>$level,
  121. "supplier_type"=>$supplier_type,
  122. "pay_type"=>$pay_type,
  123. "registercode"=>$registercode,
  124. "capital"=>$capital,
  125. "product_category"=>$product_category,
  126. "is_payment"=>$is_payment,
  127. "notice_mark"=>$notice_mark,
  128. "agreement"=>$agreement,
  129. "warehouse"=>$warehouse,
  130. "pay_day"=>$pay_day,
  131. "scope"=>$scope,
  132. "code"=>$tr,
  133. "type"=>$type,
  134. "nature"=>$nature,
  135. "legaler"=>$legaler,
  136. "addr"=>$addr,
  137. "status"=>1,
  138. "is_del"=>0,
  139. "remark"=>'',
  140. "ticket_type"=>$ticket_type,
  141. "addtime"=>date('Y-m-d H:i:s'),
  142. "updatetime"=>date("Y-m-d H:i:s"),
  143. "is_platform"=>$is_platform,
  144. "prove_img"=>$prove_img,
  145. "license_img"=>$supplier_img,
  146. "creater"=>$creater,
  147. "createrid"=>$createrid,
  148. "registertime"=>date('Y-m-d H:i:s'),
  149. "person"=>$person,
  150. "personid"=>$personid,
  151. ];
  152. if($supplier_img!==""){
  153. $ocr=new Ocr();
  154. $datwa = $ocr->query("",$supplier_img);
  155. if($datwa['code']==0 && isset($datwa['data']['result'])){
  156. $license = $datwa['data']['result'];
  157. $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
  158. $data['addr']= isset($license['address'])?$license['address']:"";
  159. $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
  160. $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
  161. $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
  162. $data['nature']= isset($license['type'])?$license['type']:"";
  163. $data['registercode']= isset($license['registration_number'])?$license['registration_number']:"";
  164. $data['ocr_status']=1;
  165. if($name!=$license['name']){
  166. $data['remark']="企业名称与营业执照不匹配";
  167. $data['status']=0;
  168. $data['ocr_status']=1;
  169. }
  170. if($registercode!=$license['registration_number'] && $registercode!=""){
  171. $data['remark'].="企业名称与营业执照不匹配";
  172. $data['status']=0;
  173. $data['ocr_status']=1;
  174. }
  175. }else{
  176. $data['remark']="营业执照识别失败";
  177. $data['status']=0;
  178. $data['ocr_status']=2;
  179. }
  180. }
  181. $join = Db::name('supplier')->insert($data,true);
  182. if($join>0){
  183. $temp = [];
  184. $temp['code']=$tr;
  185. $temp['contactor'] =$contactor;
  186. $temp['mobile'] = $mobile;
  187. $temp['position'] = $position;
  188. $temp['telephone'] =$telephone;
  189. $temp['email'] ="";
  190. $temp['is_del'] = 0;
  191. $temp['addtime'] = date("Y-m-d H:i:s");
  192. $temp['updatetime'] = date("Y-m-d H:i:s");
  193. $vp = Db::name('supplier_contact')->insert($temp);
  194. if ($vp == "") {
  195. Db::rollback();
  196. return error_show(1002, "添加失败");
  197. }
  198. Db::commit();
  199. return error_show(0,"添加成功",["id"=>$join]) ;
  200. }else{
  201. Db::rollback();
  202. return error_show(1002,"添加失败");
  203. }
  204. }catch (\Exception $e) {
  205. Db::rollback();
  206. return error_show(1003, $e->getMessage());
  207. }
  208. }
  209. public function list(){
  210. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  211. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  212. $where =[['is_del',"=",0]];
  213. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']):"";
  214. if($name !==""){
  215. $where[]=["name","like","%$name%"];
  216. }
  217. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  218. if($creater !==""){
  219. $where[] = ["creater","like","%$creater%"];
  220. }
  221. $person = isset($this->post['person']) && $this->post['person'] !=="" ? trim($this->post['person']):"";
  222. if($person !==""){
  223. $where[] = ["person","like","%$person%"];
  224. }
  225. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  226. if($status!==""){
  227. $where[]= ["status","=",$status];
  228. }
  229. $ocr_status = isset($this->post['ocr_status']) && $this->post['ocr_status'] !=="" ? intval($this->post['ocr_status']):"";
  230. if($ocr_status!==""){
  231. $where[]= ["ocr_status","=",$ocr_status];
  232. }
  233. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  234. if($start!==""){
  235. $where[]=['addtime',">=",$start];
  236. }
  237. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  238. // if($end !=""){
  239. // $where[]=['a.addtime',"<=",$end];
  240. // }
  241. // $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):"";
  242. // if($contactor !=""){
  243. // $where[]=["contactor","like","%$contactor%"];
  244. // }
  245. // $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
  246. // if($mobile !=""){
  247. // $where[] = ['mobile',"like","%$mobile%"];
  248. // }
  249. $count = Db::name('supplier')->where($where)->count();
  250. $total = ceil($count / $size);
  251. $page = $page >= $total ? $total : $page;
  252. // $list = Db::name('supplier')->alias('a')
  253. // ->join("supplier_contact b","b.code=a.code","left")
  254. // ->where($where)->page($page,$size)->order("a.addtime desc")
  255. // ->field("a.*,b.contactor,b.mobile")->select();
  256. $list = Db::name('supplier')->where($where)->page($page,$size)->order("addtime desc")->select();
  257. $var=[];
  258. foreach ($list as $value){
  259. $tem = Db::name('supplier_contact')->where(['code'=>$value['code']])->field("contactor,mobile")->find();
  260. $iten=[];
  261. $value['contactor']=$tem['contactor'];
  262. $value['mobile']=$tem['mobile'];
  263. $var[]=$value;
  264. }
  265. return app_show("0","获取成功",['list'=>$var,'count'=>$count]);
  266. }
  267. public function edit(){
  268. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  269. if($token==''){
  270. return error_show(105,"参数token不能为空");
  271. }
  272. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  273. if($id==""){
  274. return error_show(1002,"参数id不能为空");
  275. }
  276. $info = Db::name("supplier")->where(['id'=>$id,'is_del'=>0])->find();
  277. if($info==""){
  278. return error_show(1002,"未找到数据");
  279. }
  280. if($info['status']==1){
  281. return error_show(1002,"状态是启用状态,无法编辑");
  282. }
  283. $source= isset($this->post['source']) && $this->post['source']!==""? trim($this->post['source']) :"";
  284. if($source==""){
  285. return error_show(1002,"供应商来源不能为空");
  286. }
  287. $type = isset($this->post['type']) && $this->post['type']!==""? trim($this->post['type']) :"";
  288. if($type==""){
  289. return error_show(1002,"申请类型不能为空");
  290. }
  291. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !==""? trim($this->post['coop_state']):"";
  292. if($coop_state==""){
  293. return error_show(1002,"参数coop_state不能为空");
  294. }
  295. $category = isset($this->post['category']) && $this->post['category'] !==""? trim($this->post['category']):"";
  296. if($category==""){
  297. return error_show(1002,"参数category不能为空");
  298. }
  299. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !==""? trim($this->post['delivery_way']):"";
  300. if($delivery_way==""){
  301. return error_show(1002,"参数delivery_way不能为空");
  302. }
  303. $level = isset($this->post['level']) && $this->post['level'] !==""? trim($this->post['level']):"";
  304. if($level==""){
  305. return error_show(1002,"参数level不能为空");
  306. }
  307. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !==""? trim($this->post['supplier_type']):"";
  308. if($supplier_type==""){
  309. return error_show(1002,"参数supplier_type不能为空");
  310. }
  311. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !==""? trim($this->post['pay_type']):"";
  312. if($pay_type==""){
  313. return error_show(1002,"参数pay_type不能为空");
  314. }
  315. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !==""? trim($this->post['prove_img']):"";
  316. $personid = isset($this->post['personid']) && $this->post['personid'] !==""? intval($this->post['personid']):"";
  317. if($personid==""){
  318. return error_show(1002,"参数personid不能为空");
  319. }
  320. $to= GetInfoById($token,['id'=>$personid]);
  321. if(empty($to)||$to['code']!=0){
  322. return app_show(1002,"负责人信息不存在");
  323. }
  324. $telephone = isset($this->post['telephone']) && $this->post['telephone'] !=="" ? trim($this->post['telephone']):"";
  325. $person = isset($to['data']['nickname']) &&$to['data']['nickname']!="" ? $to['data']['nickname'] :"" ;
  326. $name = isset($this->post['name']) && $this->post['name'] !=="" ? trim($this->post['name']) :"";
  327. if($name==""){
  328. return error_show(1002,"数据标题不能为空");
  329. }
  330. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->where([["id","<>",$id]])->find();
  331. if ($rename!=false) {
  332. return error_show(1002, "公司名称已存在");
  333. }
  334. // $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  335. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform']!==""? intval($this->post['is_platform']) :"0";
  336. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type']!==""? trim($this->post['ticket_type']) :"";
  337. // $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  338. // $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  339. $registercode= isset($this->post['registercode']) && $this->post['registercode']!==""? trim($this->post['registercode']) :"";
  340. // $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  341. $product_category= isset($this->post['product_category']) && $this->post['product_category']!==""? trim($this->post['product_category']) :"";
  342. $is_payment= isset($this->post['is_payment']) && $this->post['is_payment']!==""?trim($this->post['is_payment']) :"";
  343. $notice_mark= isset($this->post['notice_mark']) && $this->post['notice_mark']!==""?trim($this->post['notice_mark']) :"";
  344. $agreement= isset($this->post['agreement']) && $this->post['agreement']!==""?trim($this->post['agreement']) :"";
  345. $warehouse= isset($this->post['warehouse']) && $this->post['warehouse']!==""?trim($this->post['warehouse']) :"";
  346. $pay_day= isset($this->post['pay_day']) && $this->post['pay_day']!==""?trim($this->post['pay_day']) :"";
  347. // $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  348. //// $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  349. // $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  350. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !=="" ? trim($this->post['supplier_img']):"";
  351. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor']):"";
  352. if($contactor==""){
  353. return error_show(1002,"参数contactor不能为空");
  354. }
  355. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile']):"";
  356. if($mobile==""){
  357. return error_show(1002,"参数mobile不能为空");
  358. }
  359. $position = isset($this->post['position']) && $this->post['position'] !=="" ? trim($this->post['position']):"";
  360. if($position==""){
  361. return error_show(1002,"参数position不能为空");
  362. }
  363. // if($registercode==""){
  364. // return error_show(1002,"参数registercode不能为空");
  365. // }
  366. Db::startTrans();
  367. try{
  368. $data=[
  369. "id"=>$id,
  370. "source"=>$source,
  371. "name"=>$name,
  372. "coop_state"=>$coop_state,
  373. "category"=>$category,
  374. "delivery_way"=>$delivery_way,
  375. "level"=>$level,
  376. "supplier_type"=>$supplier_type,
  377. "pay_type"=>$pay_type,
  378. "registercode"=>$registercode,
  379. "product_category"=>$product_category,
  380. "is_payment"=>$is_payment,
  381. "notice_mark"=>$notice_mark,
  382. "agreement"=>$agreement,
  383. "warehouse"=>$warehouse,
  384. "pay_day"=>$pay_day,
  385. "type"=>$type,
  386. "license_img"=>$supplier_img,
  387. "is_del"=>0,
  388. // "status"=>$info['license_img']==$supplier_img ? $info['status']:0,
  389. "ticket_type"=>$ticket_type,
  390. "updatetime"=>date("Y-m-d H:i:s"),
  391. "is_platform"=>$is_platform,
  392. "prove_img"=>$prove_img,
  393. "person"=>$person,
  394. "personid"=>$personid,
  395. "remark"=>""
  396. ];
  397. if($supplier_img!=="" &&$info['license_img']!=$supplier_img){
  398. $ocr=new Ocr();
  399. $dataw = $ocr->query("",$supplier_img);
  400. if($dataw['code']==0 && isset($dataw['data']['result'])){
  401. $license = $dataw['data']['result'];
  402. $data['legaler']= isset($license['legal_representative'])?$license['legal_representative']:"";
  403. $data['addr']= isset($license['address'])?$license['address']:"";
  404. $data['registertime']= isset($license['found_date'])? $license['found_date']:"";
  405. $data['scope']= isset($license['business_scope'])?$license['business_scope']:"";
  406. $data['capital']= isset($license['registered_capital'])?$license['registered_capital']:"";
  407. $data['nature']= isset($license['type'])?$license['type']:"";
  408. $data['registercode']=isset($license['registration_number'])? $license['registration_number']:"";//12356
  409. $data['ocr_status']=1;
  410. if($name!=$license['name']){
  411. $data['remark']="企业名称与营业执照不匹配";
  412. $data['ocr_status']=1;
  413. }
  414. if($registercode!=$license['registration_number']&&$registercode!=''){
  415. $data['remark'].="企业名称与营业执照不匹配";
  416. $data['ocr_status']=1;
  417. }
  418. }else{
  419. $data['remark']="营业执照识别失败";
  420. $data['ocr_status']=2;
  421. }
  422. }
  423. $ino = array_diff($data,$info);
  424. $tem = json_encode($ino,JSON_UNESCAPED_UNICODE);
  425. $jsp = json_encode($info,JSON_UNESCAPED_UNICODE);
  426. $join = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->save($data);
  427. if($join){
  428. ChangeLog::logAdd("1",$info['code'],$jsp,$tem,$this->post['token'],$this->post);
  429. $item = Db::name('supplier_contact')->where(['code'=>$info['code']])->find();
  430. $temp = [];
  431. isset($item['id']) && $item['id'] !== "" ? $temp['id'] =$item['id'] : '';
  432. $temp['code'] = $info['code'];
  433. $temp['contactor'] = $contactor;
  434. $temp['mobile'] = $mobile;
  435. $temp['position'] = $position;
  436. $temp['telephone'] = $telephone;
  437. $temp['email'] ="";
  438. $temp['is_del'] = 0;
  439. isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  440. $temp['updatetime'] = date("Y-m-d H:i:s");
  441. // $st = array_diff($item,$temp);
  442. // $snm =json_encode($st);
  443. $vp = Db::name('supplier_contact')->save($temp);
  444. if ($vp == "") {
  445. // ChangeLog::logAdd("1",$item['code'],$item,$snm,$this->post['token'],$this->post);
  446. Db::rollback();
  447. return error_show(1002, "更新失败");
  448. }
  449. Db::commit();
  450. return error_show(0,"编辑成功") ;
  451. }else{
  452. Db::rollback();
  453. return error_show(1002,"编辑失败");
  454. }
  455. }catch (\Exception $e) {
  456. Db::rollback();
  457. return error_show(1003, $e->getMessage());
  458. }
  459. }
  460. public function info(){
  461. $id = isset($this->post['id'])&& $this->post['id'] !=="" ? intval($this->post['id']) :"";
  462. if($id ==""){
  463. return error_show(1002,"参数id不能为空");
  464. }
  465. $info = Db::name('supplier')->where(['id'=>$id,'is_del'=>0])->find();
  466. if($info==""){
  467. return error_show(1002,"未找到数据");
  468. }
  469. $contact = Db::name("supplier_contact")->where(["code"=>$info['code'],"is_del"=>0])->find();
  470. $info['contactor']=isset($contact['contactor'])? $contact['contactor']:"";
  471. $info['mobile']=isset($contact['mobile'])? $contact['mobile']:"";
  472. $info['position']=isset($contact['position'])? $contact['position']:"";
  473. $info['email']=isset($contact['email'])? $contact['email']:"";
  474. $info['telephone']=isset($contact['telephone'])? $contact['telephone']:"";
  475. $info['supplier_img']=isset($info['license_img'])? $info['license_img']:"";
  476. return app_show(0,"获取成功",$info);
  477. }
  478. public function del(){
  479. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  480. $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  481. if($sup==false){
  482. return error_show(1002,"供应商信息不存在");
  483. }
  484. $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  485. $vam = array_diff($sup,$supp);
  486. $vap = json_encode($vam);
  487. if($supp){
  488. ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
  489. return error_show(0,"删除成功");
  490. }else{
  491. return error_show(1002,"删除失败");
  492. }
  493. }
  494. public function status(){
  495. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  496. if($id==""){
  497. return error_show(1002,"参数id不能为空");
  498. }
  499. $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  500. if(!$info){
  501. return error_show(1002,"未找到对应数据");
  502. }
  503. $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  504. if($status===""){
  505. return error_show(1002,"参数status不能为空");
  506. }
  507. if(!in_array($status,[0,1,2])){
  508. return error_show(1002,"参数status无效");
  509. }
  510. $info['status']=$status;
  511. $info['updatetime']=date("Y-m-d H:i:s");
  512. $msg = $status==1?"启用":"禁用";
  513. $update = Db::name("supplier")->save($info);
  514. return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  515. }
  516. }