Suppler.php 28 KB

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