Suppler.php 35 KB

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