Suppler.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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\facade\Config;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //供应商
  10. class Suppler extends Base
  11. {
  12. public $post = "";
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->post = $this->request->post();
  17. }
  18. public function create()
  19. {
  20. $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  21. if ($name == "") {
  22. return error_show(1002, "参数name不能为空");
  23. }
  24. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->find();
  25. if (!empty($rename)) {
  26. return error_show(1002, "公司名称已存在");
  27. }
  28. $tr = makeNo("QS");
  29. $source = isset($this->post['source']) && $this->post['source'] !== "" ? intval($this->post['source']) : "";
  30. if ($source === "") {
  31. return error_show(1002, "供应商来源不能为空");
  32. }
  33. $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  34. if ($token == '') {
  35. return error_show(105, "参数token不能为空");
  36. }
  37. $user = GetUserInfo($token);
  38. if (empty($user) || $user['code'] != 0) {
  39. return error_show(1002, "创建人数据不存在");
  40. }
  41. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  42. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  43. $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
  44. if ($personid == "") {
  45. return error_show(1002, "参数personid不能为空");
  46. }
  47. $to = GetInfoById($token, ['id' => $personid]);
  48. if (empty($to) || $to['code'] != 0) {
  49. return app_show(1002, "负责人信息不存在");
  50. }
  51. $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
  52. $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "";
  53. if ($type === "") {
  54. return error_show(1002, "申请类型不能为空");
  55. }
  56. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? intval($this->post['coop_state']) : "";
  57. if ($coop_state === "") {
  58. return error_show(1002, "参数coop_state不能为空");
  59. }
  60. $category = isset($this->post['category']) && $this->post['category'] !== "" ? intval($this->post['category']) : "";
  61. if ($category === "") {
  62. return error_show(1002, "参数category不能为空");
  63. }
  64. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? intval($this->post['delivery_way']) : "";
  65. if ($delivery_way === "") {
  66. return error_show(1002, "参数delivery_way不能为空");
  67. }
  68. $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
  69. if ($level === "") {
  70. return error_show(1002, "参数level不能为空");
  71. }
  72. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? intval($this->post['supplier_type']) : "";
  73. if ($supplier_type === "") {
  74. return error_show(1002, "参数supplier_type不能为空");
  75. }
  76. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? intval($this->post['pay_type']) : "";
  77. if ($pay_type === "") {
  78. return error_show(1002, "参数pay_type不能为空");
  79. }
  80. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
  81. // $area = isset($this->post['area']) && $this->post['area']!==""? trim($this->post['area']) :"";
  82. // $city = isset($this->post['city']) && $this->post['city']!==""? trim($this->post['city']) :"";
  83. $nature = isset($this->post['nature']) && $this->post['nature'] !== "" ? intval($this->post['nature']) : "";
  84. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
  85. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? intval($this->post['ticket_type']) : "";
  86. $legaler = isset($this->post['legaler']) && $this->post['legaler'] !== "" ? trim($this->post['legaler']) : "";
  87. $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
  88. $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
  89. $capital = isset($this->post['capital']) && $this->post['capital'] !== "" ? intval($this->post['capital']) : "";
  90. $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
  91. $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
  92. $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
  93. $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
  94. $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
  95. $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
  96. $scope = isset($this->post['scope']) && $this->post['scope'] !== "" ? trim($this->post['scope']) : "";
  97. // $status= isset($this->post['status']) && $this->post['status']!==""?intval($this->post['status']) :"1";
  98. //$registertime= isset($this->post['registertime']) && $this->post['registertime']!==""?
  99. // $this->post['registertime'] :"";
  100. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
  101. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
  102. if ($contactor == "") {
  103. return error_show(1002, "参数contactor不能为空");
  104. }
  105. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  106. if ($mobile == "") {
  107. return error_show(1002, "参数mobile不能为空");
  108. }
  109. $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
  110. $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
  111. if ($position == "") {
  112. return error_show(1002, "参数position不能为空");
  113. }
  114. $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
  115. Db::startTrans();
  116. try {
  117. $data = [
  118. "name" => $name,
  119. "source" => $source,
  120. "coop_state" => $coop_state,
  121. "category" => $category,
  122. "delivery_way" => $delivery_way,
  123. "level" => $level,
  124. "supplier_type" => $supplier_type,
  125. "pay_type" => $pay_type,
  126. "registercode" => $registercode,
  127. "capital" => $capital,
  128. "product_category" => $product_category,
  129. "is_payment" => $is_payment,
  130. "notice_mark" => $notice_mark,
  131. "agreement" => $agreement,
  132. "warehouse" => $warehouse,
  133. "pay_day" => $pay_day,
  134. "scope" => $scope,
  135. "code" => $tr,
  136. "type" => $type,
  137. "nature" => $nature,
  138. "legaler" => $legaler,
  139. "addr" => $addr,
  140. "status" => 0,
  141. "is_del" => 0,
  142. "remark" => '',
  143. "ticket_type" => $ticket_type,
  144. "addtime" => date('Y-m-d H:i:s'),
  145. "updatetime" => date("Y-m-d H:i:s"),
  146. "is_platform" => $is_platform,
  147. "prove_img" => $prove_img,
  148. "license_img" => $supplier_img,
  149. "creater" => $creater,
  150. "createrid" => $createrid,
  151. "registertime" => date('Y-m-d H:i:s'),
  152. "person" => $person,
  153. "personid" => $personid,
  154. ];
  155. if ($supplier_img !== "") {
  156. $ocr = new Ocr();
  157. $datwa = $ocr->query("", $supplier_img);
  158. if ($datwa['code'] == 0 && isset($datwa['data']['result'])) {
  159. $license = $datwa['data']['result'];
  160. $data['legaler'] = isset($license['legal_representative']) ? $license['legal_representative'] : "";
  161. $data['addr'] = isset($license['address']) ? $license['address'] : "";
  162. $data['registertime'] = isset($license['found_date']) ? $license['found_date'] : "";
  163. $data['scope'] = isset($license['business_scope']) ? $license['business_scope'] : "";
  164. $data['capital'] = isset($license['registered_capital']) ? $license['registered_capital'] : "";
  165. $data['nature'] = isset($license['type']) ? $license['type'] : "";
  166. $data['registercode'] = isset($license['registration_number']) ? $license['registration_number'] : "";
  167. $data['ocr_status'] = 1;
  168. if ($name != $license['name']) {
  169. $data['remark'] = "企业名称与营业执照不匹配";
  170. $data['status'] = 0;
  171. $data['ocr_status'] = 1;
  172. }
  173. if ($registercode != $license['registration_number'] && $registercode != "") {
  174. $data['remark'] .= "企业名称与营业执照不匹配";
  175. $data['status'] = 0;
  176. $data['ocr_status'] = 1;
  177. }
  178. } else {
  179. $data['remark'] = "营业执照识别失败";
  180. $data['status'] = 0;
  181. $data['ocr_status'] = 2;
  182. }
  183. }
  184. $join = Db::name('supplier')->insert($data, true);
  185. if ($join > 0) {
  186. $temp = [];
  187. $temp['code'] = $tr;
  188. $temp['contactor'] = $contactor;
  189. $temp['mobile'] = $mobile;
  190. $temp['position'] = $position;
  191. $temp['telephone'] = $telephone;
  192. $temp['email'] = $email;
  193. $temp['is_del'] = 0;
  194. $temp['addtime'] = date("Y-m-d H:i:s");
  195. $temp['updatetime'] = date("Y-m-d H:i:s");
  196. $vp = Db::name('supplier_contact')->insert($temp);
  197. if ($vp == "") {
  198. Db::rollback();
  199. return error_show(1002, "添加失败");
  200. }
  201. Db::commit();
  202. return app_show(0, "添加成功", ["id" => $join]);
  203. } else {
  204. Db::rollback();
  205. return error_show(1002, "添加失败");
  206. }
  207. } catch (\Exception $e) {
  208. Db::rollback();
  209. return error_show(1003, $e->getMessage());
  210. }
  211. }
  212. public function list()
  213. {
  214. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  215. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  216. $where = [['s.is_del', "=", 0]];
  217. $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  218. if ($name !== "") {
  219. $where[] = ["s.name", "like", "%$name%"];
  220. }
  221. $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  222. if ($creater !== "") {
  223. $where[] = ["s.creater", "like", "%$creater%"];
  224. }
  225. $person = isset($this->post['person']) && $this->post['person'] !== "" ? trim($this->post['person']) : "";
  226. if ($person !== "") {
  227. $where[] = ["s.person", "like", "%$person%"];
  228. }
  229. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  230. if ($status !== "") {
  231. $where[] = ["s.status", "=", $status];
  232. }
  233. $ocr_status = isset($this->post['ocr_status']) && $this->post['ocr_status'] !== "" ? intval($this->post['ocr_status']) : "";
  234. if ($ocr_status !== "") {
  235. $where[] = ["s.ocr_status", "=", $ocr_status];
  236. }
  237. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  238. if ($start !== "") {
  239. $where[] = ['s.addtime', ">=", $start];
  240. }
  241. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  242. if ($company_name !== "") $where[] = ["s.createrid", 'in', get_company_item_user_by_name($company_name)];
  243. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  244. // if($end !=""){
  245. // $where[]=['s.addtime',"<=",$end];
  246. // }
  247. // $contactor = isset($this->post['contactor']) && $this->post['contactor'] !==""? trim($this->post['contactor']):"";
  248. // if($contactor !=""){
  249. // $where[]=["s.contactor","like","%$contactor%"];
  250. // }
  251. // $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? intval($this->post['mobile']):"";
  252. // if($mobile !=""){
  253. // $where[] = ['s.mobile',"like","%$mobile%"];
  254. // }
  255. $count = Db::name('supplier')
  256. ->alias('s')
  257. ->where($where)
  258. ->count();
  259. $total = ceil($count / $size);
  260. $page = $page >= $total ? $total : $page;
  261. // $list = Db::name('supplier')->alias('a')
  262. // ->join("supplier_contact b","b.code=a.code","left")
  263. // ->where($where)->page($page,$size)->order("a.addtime desc")
  264. // ->field("a.*,b.contactor,b.mobile")->select();
  265. $list = Db::name('supplier')
  266. ->alias('s')
  267. ->field('s.*,u.itemid')
  268. ->leftJoin("depart_user u", "u.uid=s.createrid AND u.is_del=0")
  269. ->where($where)
  270. ->page($page, $size)
  271. ->order("addtime desc")
  272. ->select()
  273. ->toArray();
  274. $all_codes = Db::name('supplier_contact')
  275. ->whereIn('code', array_column($list, 'code'))
  276. ->column("id,contactor,mobile", 'code');
  277. //获取开通账号的供应商
  278. $account = checkHasAccountBySupplierNos(array_column($list,'code'));
  279. foreach ($list as &$value) {
  280. $value['contactor'] = isset($all_codes[$value['code']]['contactor']) ? $all_codes[$value['code']]['contactor'] : '';
  281. $value['mobile'] = isset($all_codes[$value['code']]['mobile']) ? $all_codes[$value['code']]['mobile'] : '';
  282. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  283. $value['has_account'] = (int)isset($account[$value['code']]);
  284. }
  285. return app_show("0", "获取成功", ['list' => $list, 'count' => $count]);
  286. }
  287. public function edit()
  288. {
  289. $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  290. if ($token == '') {
  291. return error_show(105, "参数token不能为空");
  292. }
  293. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  294. if ($id == "") {
  295. return error_show(1002, "参数id不能为空");
  296. }
  297. $info = Db::name("supplier")->where(['id' => $id, 'is_del' => 0])->find();
  298. if ($info == "") {
  299. return error_show(1002, "未找到数据");
  300. }
  301. if ($info['status'] == 1) {
  302. return error_show(1002, "状态是启用状态,无法编辑");
  303. }
  304. $source = isset($this->post['source']) && $this->post['source'] !== "" ? trim($this->post['source']) : "";
  305. if ($source == "") {
  306. return error_show(1002, "供应商来源不能为空");
  307. }
  308. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  309. if ($type == "") {
  310. return error_show(1002, "申请类型不能为空");
  311. }
  312. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? trim($this->post['coop_state']) : "";
  313. if ($coop_state == "") {
  314. return error_show(1002, "参数coop_state不能为空");
  315. }
  316. $category = isset($this->post['category']) && $this->post['category'] !== "" ? trim($this->post['category']) : "";
  317. if ($category == "") {
  318. return error_show(1002, "参数category不能为空");
  319. }
  320. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? trim($this->post['delivery_way']) : "";
  321. if ($delivery_way == "") {
  322. return error_show(1002, "参数delivery_way不能为空");
  323. }
  324. $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
  325. if ($level == "") {
  326. return error_show(1002, "参数level不能为空");
  327. }
  328. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? trim($this->post['supplier_type']) : "";
  329. if ($supplier_type == "") {
  330. return error_show(1002, "参数supplier_type不能为空");
  331. }
  332. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? trim($this->post['pay_type']) : "";
  333. if ($pay_type == "") {
  334. return error_show(1002, "参数pay_type不能为空");
  335. }
  336. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
  337. $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
  338. if ($personid == "") {
  339. return error_show(1002, "参数personid不能为空");
  340. }
  341. $to = GetInfoById($token, ['id' => $personid]);
  342. if (empty($to) || $to['code'] != 0) {
  343. return app_show(1002, "负责人信息不存在");
  344. }
  345. $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
  346. $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
  347. $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  348. if ($name == "") {
  349. return error_show(1002, "数据标题不能为空");
  350. }
  351. $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->where([["id", "<>", $id]])->find();
  352. if ($rename != false) {
  353. return error_show(1002, "公司名称已存在");
  354. }
  355. // $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  356. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
  357. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? trim($this->post['ticket_type']) : "";
  358. // $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  359. // $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  360. $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
  361. // $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  362. $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
  363. $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
  364. $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
  365. $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
  366. $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
  367. $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
  368. // $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  369. //// $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  370. // $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  371. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
  372. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
  373. if ($contactor == "") {
  374. return error_show(1002, "参数contactor不能为空");
  375. }
  376. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  377. if ($mobile == "") {
  378. return error_show(1002, "参数mobile不能为空");
  379. }
  380. $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
  381. if ($position == "") {
  382. return error_show(1002, "参数position不能为空");
  383. }
  384. $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
  385. // if($registercode==""){
  386. // return error_show(1002,"参数registercode不能为空");
  387. // }
  388. Db::startTrans();
  389. try {
  390. $data = [
  391. "id" => $id,
  392. "source" => $source,
  393. "name" => $name,
  394. "coop_state" => $coop_state,
  395. "category" => $category,
  396. "delivery_way" => $delivery_way,
  397. "level" => $level,
  398. "supplier_type" => $supplier_type,
  399. "pay_type" => $pay_type,
  400. "registercode" => $registercode,
  401. "product_category" => $product_category,
  402. "is_payment" => $is_payment,
  403. "notice_mark" => $notice_mark,
  404. "agreement" => $agreement,
  405. "warehouse" => $warehouse,
  406. "pay_day" => $pay_day,
  407. "type" => $type,
  408. "license_img" => $supplier_img,
  409. "is_del" => 0,
  410. // "status"=>$info['license_img']==$supplier_img ? $info['status']:0,
  411. "ticket_type" => $ticket_type,
  412. "updatetime" => date("Y-m-d H:i:s"),
  413. "is_platform" => $is_platform,
  414. "prove_img" => $prove_img,
  415. "person" => $person,
  416. "personid" => $personid,
  417. "remark" => ""
  418. ];
  419. if ($supplier_img !== "" && $info['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. $ino = array_diff($data, $info);
  446. $tem = json_encode($ino, JSON_UNESCAPED_UNICODE);
  447. $jsp = json_encode($info, JSON_UNESCAPED_UNICODE);
  448. $join = Db::name('supplier')->where(['id' => $id, 'is_del' => 0])->save($data);
  449. if ($join) {
  450. ChangeLog::logAdd("1", $info['code'], $jsp, $tem, $this->post['token'], $this->post);
  451. $item = Db::name('supplier_contact')->where(['code' => $info['code']])->find();
  452. $temp = [];
  453. isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
  454. $temp['code'] = $info['code'];
  455. $temp['contactor'] = $contactor;
  456. $temp['mobile'] = $mobile;
  457. $temp['position'] = $position;
  458. $temp['telephone'] = $telephone;
  459. $temp['email'] = $email;
  460. $temp['is_del'] = 0;
  461. isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  462. $temp['updatetime'] = date("Y-m-d H:i:s");
  463. // $st = array_diff($item,$temp);
  464. // $snm =json_encode($st);
  465. $vp = Db::name('supplier_contact')->save($temp);
  466. if ($vp == "") {
  467. // ChangeLog::logAdd("1",$item['code'],$item,$snm,$this->post['token'],$this->post);
  468. Db::rollback();
  469. return error_show(1002, "更新失败");
  470. }
  471. Db::commit();
  472. return app_show(0, "编辑成功");
  473. } else {
  474. Db::rollback();
  475. return error_show(1002, "编辑失败");
  476. }
  477. } catch (\Exception $e) {
  478. Db::rollback();
  479. return error_show(1003, $e->getMessage());
  480. }
  481. }
  482. public function info()
  483. {
  484. $code = isset($this->post['code']) && $this->post['code'] !== "" ? trim($this->post['code']) : "";
  485. if ($code == "") {
  486. return error_show(1002, "参数code不能为空");
  487. }
  488. $info = Db::name('supplier')->where(['code' => $code, 'is_del' => 0])->find();
  489. if ($info == "") {
  490. return error_show(1002, "未找到数据");
  491. }
  492. $contact = Db::name("supplier_contact")->where(["code" => $info['code'], "is_del" => 0])->find();
  493. $info['contactor'] = isset($contact['contactor']) ? $contact['contactor'] : "";
  494. $info['mobile'] = isset($contact['mobile']) ? $contact['mobile'] : "";
  495. $info['position'] = isset($contact['position']) ? $contact['position'] : "";
  496. $info['email'] = isset($contact['email']) ? $contact['email'] : "";
  497. $info['telephone'] = isset($contact['telephone']) ? $contact['telephone'] : "";
  498. $info['supplier_img'] = isset($info['license_img']) ? $info['license_img'] : "";
  499. return app_show(0, "获取成功", $info);
  500. }
  501. //删除 供应商
  502. public function del()
  503. {
  504. $id = $this->request->filter('trim')->post('id/d', 0);
  505. $sup = Db::name("supplier")
  506. ->where(['id' => $id, 'is_del' => 0])
  507. ->find();
  508. if (empty($sup)) return error_show(1005, '未找到对应数据');
  509. Db::startTrans();
  510. try {
  511. //维护供应商表
  512. $supp = ['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")];
  513. Db::name("supplier")
  514. ->where(['id' => $id, 'is_del' => 0])
  515. ->update($supp);
  516. $vam = array_intersect_key($sup, $supp);//比较两个数组的键名,并返回交集
  517. ChangeLog::logAdd("1", $sup['code'], json_encode($sup, JSON_UNESCAPED_UNICODE), json_encode($vam, JSON_UNESCAPED_UNICODE), $this->post['token'], $this->post);
  518. Db::commit();
  519. return app_show(0, '删除成功');
  520. } catch (\Exception $exception) {
  521. Db::rollback();
  522. return error_show(1005, '删除失败' . $exception->getMessage());
  523. }
  524. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  525. // $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  526. // if($sup==false){
  527. // return error_show(1002,"供应商信息不存在");
  528. // }
  529. // $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  530. // $vam = array_diff($sup,$supp);
  531. // $vap = json_encode($vam);
  532. // if($supp){
  533. // ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
  534. //
  535. // //维护联系人账号
  536. // $res = SupplierUser::where([
  537. // 'is_del' => SupplierUser::$is_del_normal,
  538. // 'status' => SupplierUser::$status_normal,
  539. // 'type' => SupplierUser::$type_default
  540. // ])->whereFindInSet('supplierNos', $sup['code'])->save([
  541. // 'is_del' => SupplierUser::$is_del_deleted,
  542. // 'updatetime' => date('Y-m-d H:i:s')
  543. // ]);
  544. // if (!$res) return error_show('删除联系人账号失败');
  545. //
  546. // return error_show(0,"删除成功");
  547. // }else{
  548. // return error_show(1002,"删除失败");
  549. // }
  550. }
  551. //启/禁用 供应商
  552. public function status()
  553. {
  554. $param = $this->request->filter('trim')->only(['id', 'status'], 'post');
  555. $val = Validate::rule(['id' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1,2']);
  556. if (!$val->check($param)) return error_show(1005, $val->getError());
  557. $msg = $param['status'] == 1 ? "启用" : "禁用";
  558. $info = Db::name("supplier")
  559. ->alias('a')
  560. ->field('a.id,a.code,a.status,b.mobile')
  561. ->leftJoin('supplier_contact b', 'b.code=a.code')
  562. ->where(['a.id' => $param['id'], 'a.is_del' => 0])
  563. ->find();
  564. if (empty($info)) return error_show(1005, '未找到对应数据');
  565. if ($info['status'] == $param['status']) return error_show(1005, '不能重复' . $msg);
  566. Db::startTrans();
  567. try {
  568. //维护供应商表
  569. Db::name("supplier")
  570. ->where('id', $param['id'])
  571. ->where('status', '<>', $param['status'])
  572. ->save([
  573. 'status' => $param['status'],
  574. 'updatetime' => date("Y-m-d H:i:s"),
  575. ]);
  576. Db::commit();
  577. return app_show(0, $msg . '成功');
  578. } catch (\Exception $exception) {
  579. Db::rollback();
  580. return error_show(1005, $exception->getMessage());
  581. }
  582. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  583. // if($id==""){
  584. // return error_show(1002,"参数id不能为空");
  585. // }
  586. // $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  587. // if(!$info){
  588. // return error_show(1002,"未找到对应数据");
  589. // }
  590. // $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  591. // if($status===""){
  592. // return error_show(1002,"参数status不能为空");
  593. // }
  594. // if(!in_array($status,[0,1,2])){
  595. // return error_show(1002,"参数status无效");
  596. // }
  597. // $info['status']=$status;
  598. // $info['updatetime']=date("Y-m-d H:i:s");
  599. // $msg = $status==1?"启用":"禁用";
  600. // $update = Db::name("supplier")->save($info);
  601. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  602. }
  603. }