Suppler.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. // $info = Db::name("supplier")->where(['id' => $id, 'is_del' => 0])->find();
  303. $code = $this->request->only(['code' => ''], 'post', 'trim');
  304. $userCommon = \app\admin\common\User::getIns();
  305. $info = $userCommon->handle('sInfo', $code);
  306. if (!isset($info['code']) || $info['code'] != 0) return json_show($info['code'], $info['message']);
  307. //
  308. if ($info['data']['status'] == 1) return json_show(1002, "状态是启用状态,无法编辑");
  309. $source = isset($this->post['source']) && $this->post['source'] !== "" ? trim($this->post['source']) : "";
  310. if ($source == "") {
  311. return error_show(1002, "供应商来源不能为空");
  312. }
  313. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  314. if ($type == "") {
  315. return error_show(1002, "申请类型不能为空");
  316. }
  317. $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? trim($this->post['coop_state']) : "";
  318. if ($coop_state == "") {
  319. return error_show(1002, "参数coop_state不能为空");
  320. }
  321. $category = isset($this->post['category']) && $this->post['category'] !== "" ? trim($this->post['category']) : "";
  322. if ($category == "") {
  323. return error_show(1002, "参数category不能为空");
  324. }
  325. $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? trim($this->post['delivery_way']) : "";
  326. if ($delivery_way == "") {
  327. return error_show(1002, "参数delivery_way不能为空");
  328. }
  329. $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
  330. if ($level == "") {
  331. return error_show(1002, "参数level不能为空");
  332. }
  333. $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? trim($this->post['supplier_type']) : "";
  334. if ($supplier_type == "") {
  335. return error_show(1002, "参数supplier_type不能为空");
  336. }
  337. $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? trim($this->post['pay_type']) : "";
  338. if ($pay_type == "") {
  339. return error_show(1002, "参数pay_type不能为空");
  340. }
  341. $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
  342. $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
  343. if ($personid == "") {
  344. return error_show(1002, "参数personid不能为空");
  345. }
  346. $to = GetInfoById($token, ['id' => $personid]);
  347. if (empty($to) || $to['code'] != 0) {
  348. return app_show(1002, "负责人信息不存在");
  349. }
  350. $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
  351. $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
  352. $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  353. if ($name == "") {
  354. return error_show(1002, "数据标题不能为空");
  355. }
  356. // $rename = Db::name('supplier')->where(['is_del' => 0, 'name' => $name])->where([["id", "<>", $id]])->find();
  357. // if ($rename != false) {
  358. // return error_show(1002, "公司名称已存在");
  359. // }
  360. // $nature = isset($this->post['nature']) && $this->post['nature']!==""? trim($this->post['nature']) :"";
  361. $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
  362. $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? trim($this->post['ticket_type']) : "";
  363. // $legaler = isset($this->post['legaler']) && $this->post['legaler']!==""? trim($this->post['legaler']) :"";
  364. // $addr = isset($this->post['addr']) && $this->post['addr']!==""? trim($this->post['addr']) :"";
  365. $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
  366. // $capital= isset($this->post['capital']) && $this->post['capital']!==""? intval($this->post['capital']) :"";
  367. $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
  368. $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
  369. $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
  370. $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
  371. $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
  372. $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
  373. // $scope= isset($this->post['scope']) && $this->post['scope']!==""?trim($this->post['scope']) :"";
  374. //// $status= isset($this->post['status']) && $this->post['status']!==""?trim($this->post['status']) :"";
  375. // $registertime= isset($this->post['registertime']) && $this->post['registertime']!==""? $this->post['registertime'] :"";
  376. $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
  377. $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
  378. if ($contactor == "") {
  379. return error_show(1002, "参数contactor不能为空");
  380. }
  381. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
  382. if ($mobile == "") {
  383. return error_show(1002, "参数mobile不能为空");
  384. }
  385. $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
  386. if ($position == "") {
  387. return error_show(1002, "参数position不能为空");
  388. }
  389. $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
  390. // if($registercode==""){
  391. // return error_show(1002,"参数registercode不能为空");
  392. // }
  393. // Db::startTrans();
  394. // try {
  395. $data = [
  396. "id" => $id,
  397. "source" => $source,
  398. "name" => $name,
  399. "coop_state" => $coop_state,
  400. "category" => $category,
  401. "delivery_way" => $delivery_way,
  402. "level" => $level,
  403. "supplier_type" => $supplier_type,
  404. "pay_type" => $pay_type,
  405. "registercode" => $registercode,
  406. "product_category" => $product_category,
  407. "is_payment" => $is_payment,
  408. "notice_mark" => $notice_mark,
  409. "agreement" => $agreement,
  410. "warehouse" => $warehouse,
  411. "pay_day" => $pay_day,
  412. "type" => $type,
  413. "license_img" => $supplier_img,
  414. "is_del" => 0,
  415. // "status"=>$info['data']['license_img']==$supplier_img ? $info['data']['status']:0,
  416. "ticket_type" => $ticket_type,
  417. "updatetime" => date("Y-m-d H:i:s"),
  418. "is_platform" => $is_platform,
  419. "prove_img" => $prove_img,
  420. "person" => $person,
  421. "personid" => $personid,
  422. "remark" => "",
  423. 'updaterid' => $this->uid,
  424. 'updater' => $this->uname,
  425. ];
  426. if ($supplier_img !== "" && $info['data']['license_img'] != $supplier_img) {
  427. $ocr = new Ocr();
  428. $dataw = $ocr->query("", $supplier_img);
  429. if ($dataw['code'] == 0 && isset($dataw['data']['result'])) {
  430. $license = $dataw['data']['result'];
  431. $data['legaler'] = isset($license['legal_representative']) ? $license['legal_representative'] : "";
  432. $data['addr'] = isset($license['address']) ? $license['address'] : "";
  433. $data['registertime'] = isset($license['found_date']) ? $license['found_date'] : "";
  434. $data['scope'] = isset($license['business_scope']) ? $license['business_scope'] : "";
  435. $data['capital'] = isset($license['registered_capital']) ? $license['registered_capital'] : "";
  436. $data['nature'] = isset($license['type']) ? $license['type'] : "";
  437. $data['registercode'] = isset($license['registration_number']) ? $license['registration_number'] : "";//12356
  438. $data['ocr_status'] = 1;
  439. if ($name != $license['name']) {
  440. $data['remark'] = "企业名称与营业执照不匹配";
  441. $data['ocr_status'] = 1;
  442. }
  443. if ($registercode != $license['registration_number'] && $registercode != '') {
  444. $data['remark'] .= "企业名称与营业执照不匹配";
  445. $data['ocr_status'] = 1;
  446. }
  447. } else {
  448. $data['remark'] = "营业执照识别失败";
  449. $data['ocr_status'] = 2;
  450. }
  451. }
  452. // $ino = array_diff($data, $info['data']);
  453. // $tem = json_encode($ino, JSON_UNESCAPED_UNICODE);
  454. // $jsp = json_encode($info['data'], JSON_UNESCAPED_UNICODE);
  455. // $join = Db::name('supplier')->where(['id' => $id, 'is_del' => 0])->save($data);
  456. // if ($join) {
  457. // ChangeLog::logAdd("1", $info['data']['code'], $jsp, $tem, $this->post['token'], $this->post);
  458. // $item = Db::name('supplier_contact')->where(['code' => $info['data']['code']])->find();
  459. $temp = [];
  460. // isset($item['id']) && $item['id'] !== "" ? $temp['id'] = $item['id'] : '';
  461. $temp['code'] = $info['data']['code'];
  462. $temp['contactor'] = $contactor;
  463. $temp['mobile'] = $mobile;
  464. $temp['position'] = $position;
  465. $temp['telephone'] = $telephone;
  466. $temp['email'] = $email;
  467. $temp['is_del'] = 0;
  468. // isset($item['id']) && $item['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  469. $temp['updatetime'] = date("Y-m-d H:i:s");
  470. // $st = array_diff($item,$temp);
  471. // $snm =json_encode($st);
  472. // $vp = Db::name('supplier_contact')->save($temp);
  473. // if ($vp == "") {
  474. // ChangeLog::logAdd("1",$item['code'],$item,$snm,$this->post['token'],$this->post);
  475. // Db::rollback();
  476. // return error_show(1002, "更新失败");
  477. // }
  478. $res = $userCommon->handle('sEdit', ['data' => $data, 'contact' => $temp]);
  479. Db::startTrans();
  480. try {
  481. if ($info['data']['personid'] != $personid) {
  482. $good = Db::name("good_basic")->where(["supplierNo" => $info['data']['code'], "is_del" => 0])->column('id');
  483. if (!empty($good)) {
  484. $up = Db::name("good_basic")->where(["id" => $good])->update(["chargerid" => $personid, "charger" => $person, "updatetime" => date("Y-m-d H:i:s")]);
  485. if ($up == false) throw new Exception("商品负责人更新失败");
  486. }
  487. }
  488. //更新同一个供应商下虚拟仓的负责人
  489. Db::name('warehouse_info')
  490. ->where(['is_del' => 0, 'supplierNo' => $code['code'], 'wsm_type' => 2])
  491. ->update(['contactor' => $data['personid'], 'contactor_name' => $data['person']]);
  492. Db::commit();
  493. return json_show($res['code'], $res['message'], $res['data']);
  494. } catch (Exception $exception) {
  495. Db::rollback();
  496. return json_show(1004, $exception->getMessage());
  497. }
  498. // Db::commit();
  499. // return app_show(0, "编辑成功");
  500. // } else {
  501. // Db::rollback();
  502. // return error_show(1002, "编辑失败");
  503. // }
  504. // } catch (\Exception $e) {
  505. // Db::rollback();
  506. // return error_show(1003, $e->getMessage());
  507. // }
  508. }
  509. public function info()
  510. {
  511. $code = $this->request->only(['code' => ''], 'post', 'trim');
  512. $userCommon = \app\admin\common\User::getIns();
  513. $rs = $userCommon->handle('sInfo', $code);
  514. return json_show($rs['code'], $rs['message'], $rs['data']);
  515. // if ($code == "") {
  516. // return error_show(1002, "参数code不能为空");
  517. // }
  518. // $info = Db::name('supplier')->where(['code' => $code, 'is_del' => 0])->find();
  519. // if ($info == "") {
  520. // return error_show(1002, "未找到数据");
  521. // }
  522. // $contact = Db::name("supplier_contact")->where(["code" => $info['code'], "is_del" => 0])->find();
  523. // $info['contactor'] = isset($contact['contactor']) ? $contact['contactor'] : "";
  524. // $info['mobile'] = isset($contact['mobile']) ? $contact['mobile'] : "";
  525. // $info['position'] = isset($contact['position']) ? $contact['position'] : "";
  526. // $info['email'] = isset($contact['email']) ? $contact['email'] : "";
  527. // $info['telephone'] = isset($contact['telephone']) ? $contact['telephone'] : "";
  528. // $info['supplier_img'] = isset($info['license_img']) ? $info['license_img'] : "";
  529. // return app_show(0, "获取成功", $info);
  530. }
  531. //删除 供应商
  532. public function del()
  533. {
  534. $param = $this->request->only(['id' => 0], 'post', 'trim');
  535. $userCommon = \app\admin\common\User::getIns();
  536. $rs = $userCommon->handle('delete', [
  537. 'ids' => [$param['id']],
  538. 'type' => 3,
  539. 'updater' => $this->uname,
  540. 'updaterid' => $this->uid,
  541. ]);
  542. return json_show($rs['code'], $rs['message'], $rs['data']);
  543. // $sup = Db::name("supplier")
  544. // ->where(['id' => $id, 'is_del' => 0])
  545. // ->find();
  546. // if (empty($sup)) return error_show(1005, '未找到对应数据');
  547. //
  548. // Db::startTrans();
  549. // try {
  550. // //维护供应商表
  551. // $supp = ['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")];
  552. // Db::name("supplier")
  553. // ->where(['id' => $id, 'is_del' => 0])
  554. // ->update($supp);
  555. //
  556. // $vam = array_intersect_key($sup, $supp);//比较两个数组的键名,并返回交集
  557. // ChangeLog::logAdd("1", $sup['code'], json_encode($sup, JSON_UNESCAPED_UNICODE), json_encode($vam, JSON_UNESCAPED_UNICODE), $this->post['token'], $this->post);
  558. // Db::commit();
  559. // return app_show(0, '删除成功');
  560. // } catch (\Exception $exception) {
  561. // Db::rollback();
  562. // return error_show(1005, '删除失败' . $exception->getMessage());
  563. // }
  564. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
  565. // $sup = Db::name('supplier')->where(["is_del"=>0,'id'=>$id])->find();
  566. // if($sup==false){
  567. // return error_show(1002,"供应商信息不存在");
  568. // }
  569. // $supp= Db::name('supplier')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  570. // $vam = array_diff($sup,$supp);
  571. // $vap = json_encode($vam);
  572. // if($supp){
  573. // ChangeLog::logAdd("1",$sup['code'],$sup,$vap,$this->post['token'],$this->post);
  574. //
  575. // //维护联系人账号
  576. // $res = SupplierUser::where([
  577. // 'is_del' => SupplierUser::$is_del_normal,
  578. // 'status' => SupplierUser::$status_normal,
  579. // 'type' => SupplierUser::$type_default
  580. // ])->whereFindInSet('supplierNos', $sup['code'])->save([
  581. // 'is_del' => SupplierUser::$is_del_deleted,
  582. // 'updatetime' => date('Y-m-d H:i:s')
  583. // ]);
  584. // if (!$res) return error_show('删除联系人账号失败');
  585. //
  586. // return error_show(0,"删除成功");
  587. // }else{
  588. // return error_show(1002,"删除失败");
  589. // }
  590. }
  591. //启/禁用 供应商
  592. public function status()
  593. {
  594. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  595. $val = Validate::rule([
  596. 'id' => 'require|number|gt:0',
  597. 'status|状态' => 'require|number|in:0,1'
  598. ]);
  599. if (!$val->check($param)) return json_show(1005, $val->getError());
  600. $userCommon = \app\admin\common\User::getIns();
  601. $rs = $userCommon->handle('status', [
  602. 'id' => $param['id'],
  603. 'status' => $param['status'],
  604. 'type' => 3,
  605. 'updater' => $this->uname,
  606. 'updaterid' => $this->uid,
  607. ]);
  608. return json_show($rs['code'], $rs['message'], $rs['data']);
  609. // $param = $this->request->filter('trim')->only(['id', 'status'], 'post');
  610. //
  611. // $val = Validate::rule(['id' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1,2']);
  612. //
  613. // if (!$val->check($param)) return error_show(1005, $val->getError());
  614. // $msg = $param['status'] == 1 ? "启用" : "禁用";
  615. // $info = Db::name("supplier")
  616. // ->alias('a')
  617. // ->field('a.id,a.code,a.status,b.mobile')
  618. // ->leftJoin('supplier_contact b', 'b.code=a.code')
  619. // ->where(['a.id' => $param['id'], 'a.is_del' => 0])
  620. // ->find();
  621. // if (empty($info)) return error_show(1005, '未找到对应数据');
  622. // if ($info['status'] == $param['status']) return error_show(1005, '不能重复' . $msg);
  623. // Db::startTrans();
  624. // try {
  625. // //维护供应商表
  626. // Db::name("supplier")
  627. // ->where('id', $param['id'])
  628. // ->where('status', '<>', $param['status'])
  629. // ->save([
  630. // 'status' => $param['status'],
  631. // 'updatetime' => date("Y-m-d H:i:s"),
  632. // ]);
  633. //
  634. // Db::commit();
  635. // return app_show(0, $msg . '成功');
  636. // } catch (\Exception $exception) {
  637. // Db::rollback();
  638. // return error_show(1005, $exception->getMessage());
  639. // }
  640. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  641. // if($id==""){
  642. // return error_show(1002,"参数id不能为空");
  643. // }
  644. // $info = Db::name("supplier")->where([["id","=",$id],["is_del","=",0]])->find();
  645. // if(!$info){
  646. // return error_show(1002,"未找到对应数据");
  647. // }
  648. // $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  649. // if($status===""){
  650. // return error_show(1002,"参数status不能为空");
  651. // }
  652. // if(!in_array($status,[0,1,2])){
  653. // return error_show(1002,"参数status无效");
  654. // }
  655. // $info['status']=$status;
  656. // $info['updatetime']=date("Y-m-d H:i:s");
  657. // $msg = $status==1?"启用":"禁用";
  658. // $update = Db::name("supplier")->save($info);
  659. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  660. }
  661. //供应商升级成业务公司
  662. public function upgrade(){
  663. $param = $this->request->filter('trim')->post();
  664. $userCommon = \app\admin\common\User::getIns();
  665. $param['uid']=$this->uid;
  666. $param['uname']=$this->uname;
  667. $rs = $userCommon->handle('upgrade', $param);
  668. if (isset($rs['code']) && $rs['code'] == 0) {
  669. //更新用户和角色关联表的数据
  670. Db::name('user_role')
  671. ->where(['companyNo' => $param['code'], 'company_type' => 1])
  672. ->update(['company_type' => 2]);
  673. }
  674. return json_show($rs['code'], $rs['message'], $rs['data']);
  675. }
  676. }