Suppler.php 35 KB

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