123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- <?php
- namespace app\admin\controller;
- use app\admin\common\Ocr;
- use app\admin\model\ChangeLog;
- use think\App;
- use think\Exception;
- use think\facade\Config;
- use think\facade\Db;
- use think\facade\Validate;
- class Suppler extends Base
- {
- public function create()
- {
- $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
- if ($name == "") {
- return error_show(1002, "参数name不能为空");
- }
- $tr = makeNo("QS");
- $source = isset($this->post['source']) && $this->post['source'] !== "" ? intval($this->post['source']) : "";
- if ($source === "") {
- return error_show(1002, "供应商来源不能为空");
- }
- $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
- $createrid = $this->uid;
- $creater = $this->uname;
- $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
- if ($personid == "") {
- return error_show(1002, "参数personid不能为空");
- }
- $to = GetInfoById($token, ['id' => $personid]);
- if (empty($to) || $to['code'] != 0) {
- return app_show(1002, "负责人信息不存在");
- }
- $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
- $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : "";
- if ($type === "") {
- return error_show(1002, "申请类型不能为空");
- }
- $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? intval($this->post['coop_state']) : "";
- if ($coop_state === "") {
- return error_show(1002, "参数coop_state不能为空");
- }
- $category = isset($this->post['category']) && $this->post['category'] !== "" ? intval($this->post['category']) : "";
- if ($category === "") {
- return error_show(1002, "参数category不能为空");
- }
- $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? intval($this->post['delivery_way']) : "";
- if ($delivery_way === "") {
- return error_show(1002, "参数delivery_way不能为空");
- }
- $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
- if ($level === "") {
- return error_show(1002, "参数level不能为空");
- }
- $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? intval($this->post['supplier_type']) : "";
- if ($supplier_type === "") {
- return error_show(1002, "参数supplier_type不能为空");
- }
- $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? intval($this->post['pay_type']) : "";
- if ($pay_type === "") {
- return error_show(1002, "参数pay_type不能为空");
- }
- $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
-
-
- $nature = isset($this->post['nature']) && $this->post['nature'] !== "" ? intval($this->post['nature']) : "";
- $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
- $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? intval($this->post['ticket_type']) : "";
- $legaler = isset($this->post['legaler']) && $this->post['legaler'] !== "" ? trim($this->post['legaler']) : "";
- $addr = isset($this->post['addr']) && $this->post['addr'] !== "" ? trim($this->post['addr']) : "";
- $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
- $capital = isset($this->post['capital']) && $this->post['capital'] !== "" ? intval($this->post['capital']) : "";
- $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
- $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
- $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
- $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
- $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
- $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
- $scope = isset($this->post['scope']) && $this->post['scope'] !== "" ? trim($this->post['scope']) : "";
-
-
-
- $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
- $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
- if ($contactor == "") {
- return error_show(1002, "参数contactor不能为空");
- }
- $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
- if ($mobile == "") {
- return error_show(1002, "参数mobile不能为空");
- }
- $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
- $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
- if ($position == "") {
- return error_show(1002, "参数position不能为空");
- }
- $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
- $date = date('Y-m-d H:i:s');
- $data = [
- "name" => $name,
- "source" => $source,
- "coop_state" => $coop_state,
- "category" => $category,
- "delivery_way" => $delivery_way,
- "level" => $level,
- "supplier_type" => $supplier_type,
- "pay_type" => $pay_type,
- "registercode" => $registercode,
- "capital" => $capital,
- "product_category" => $product_category,
- "is_payment" => $is_payment,
- "notice_mark" => $notice_mark,
- "agreement" => $agreement,
- "warehouse" => $warehouse,
- "pay_day" => $pay_day,
- "scope" => $scope,
- "code" => $tr,
- "type" => $type,
- "nature" => $nature,
- "legaler" => $legaler,
- "addr" => $addr,
- "status" => 0,
- "is_del" => 0,
- "remark" => '',
- "ticket_type" => $ticket_type,
- "addtime" => $date,
- "updatetime" => $date,
- "is_platform" => $is_platform,
- "prove_img" => $prove_img,
- "license_img" => $supplier_img,
- "creater" => $creater,
- "createrid" => $createrid,
- "registertime" => $date,
- "person" => $person,
- "personid" => $personid,
- ];
- if ($supplier_img !== "") {
- $ocr = new Ocr();
- $datwa = $ocr->query("", $supplier_img);
- if ($datwa['code'] == 0 && isset($datwa['data']['result'])) {
- $license = $datwa['data']['result'];
- $data['legaler'] = isset($license['legal_representative']) ? $license['legal_representative'] : "";
- $data['addr'] = isset($license['address']) ? $license['address'] : "";
- $data['registertime'] = isset($license['found_date']) ? $license['found_date'] : "";
- $data['scope'] = isset($license['business_scope']) ? $license['business_scope'] : "";
- $data['capital'] = isset($license['registered_capital']) ? $license['registered_capital'] : "";
- $data['nature'] = isset($license['type']) ? $license['type'] : "";
- $data['registercode'] = isset($license['registration_number']) ? $license['registration_number'] : "";
- $data['ocr_status'] = 1;
- if ($name != $license['name']) {
- $data['remark'] = "企业名称与营业执照不匹配";
- $data['status'] = 0;
- $data['ocr_status'] = 1;
- }
- if ($registercode != $license['registration_number'] && $registercode != "") {
- $data['remark'] .= "企业名称与营业执照不匹配";
- $data['status'] = 0;
- $data['ocr_status'] = 1;
- }
- } else {
- $data['remark'] = "营业执照识别失败";
- $data['status'] = 0;
- $data['ocr_status'] = 2;
- }
- }
- $temp = [];
- $temp['code'] = $tr;
- $temp['contactor'] = $contactor;
- $temp['mobile'] = $mobile;
- $temp['position'] = $position;
- $temp['telephone'] = $telephone;
- $temp['email'] = $email;
- $temp['is_del'] = 0;
- $temp['addtime'] = $date;
- $temp['updatetime'] = $date;
- $userCommon = \app\admin\common\User::getIns();
- $rs = $userCommon->handle('sCreate', ['data' => $data, 'contact' => $temp]);
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
- public function list()
- {
- $param = $this->request->only(['page' => 1, 'size' => 10, 'name' => '', 'creater' => '', 'person' => '', 'status' => '', 'ocr_status' => '', 'start' => '', 'end' => '', 'company_name' => ''], 'post', 'trim');
- $userCommon = \app\admin\common\User::getIns();
- $rs = $userCommon->handle('sGetList', $param);
- return json_show($rs['code'], $rs['message'], $rs['data']);
-
- }
- public function edit()
- {
- $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
- if ($token == '') {
- return error_show(105, "参数token不能为空");
- }
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $code = $this->request->only(['code' => ''], 'post', 'trim');
- $userCommon = \app\admin\common\User::getIns();
- $info = $userCommon->handle('sInfo', $code);
- if (!isset($info['code']) || $info['code'] != 0) return json_show($info['code'], $info['message']);
- if ($info['data']['status'] == 1) return json_show(1002, "状态是启用状态,无法编辑");
- $source = isset($this->post['source']) && $this->post['source'] !== "" ? trim($this->post['source']) : "";
- if ($source == "") {
- return error_show(1002, "供应商来源不能为空");
- }
- $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
- if ($type == "") {
- return error_show(1002, "申请类型不能为空");
- }
- $coop_state = isset($this->post['coop_state']) && $this->post['coop_state'] !== "" ? trim($this->post['coop_state']) : "";
- if ($coop_state == "") {
- return error_show(1002, "参数coop_state不能为空");
- }
- $category = isset($this->post['category']) && $this->post['category'] !== "" ? trim($this->post['category']) : "";
- if ($category == "") {
- return error_show(1002, "参数category不能为空");
- }
- $delivery_way = isset($this->post['delivery_way']) && $this->post['delivery_way'] !== "" ? trim($this->post['delivery_way']) : "";
- if ($delivery_way == "") {
- return error_show(1002, "参数delivery_way不能为空");
- }
- $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "";
- if ($level == "") {
- return error_show(1002, "参数level不能为空");
- }
- $supplier_type = isset($this->post['supplier_type']) && $this->post['supplier_type'] !== "" ? trim($this->post['supplier_type']) : "";
- if ($supplier_type == "") {
- return error_show(1002, "参数supplier_type不能为空");
- }
- $pay_type = isset($this->post['pay_type']) && $this->post['pay_type'] !== "" ? trim($this->post['pay_type']) : "";
- if ($pay_type == "") {
- return error_show(1002, "参数pay_type不能为空");
- }
- $prove_img = isset($this->post['prove_img']) && $this->post['prove_img'] !== "" ? trim($this->post['prove_img']) : "";
- $personid = isset($this->post['personid']) && $this->post['personid'] !== "" ? intval($this->post['personid']) : "";
- if ($personid == "") {
- return error_show(1002, "参数personid不能为空");
- }
- $to = GetInfoById($token, ['id' => $personid]);
- if (empty($to) || $to['code'] != 0) {
- return app_show(1002, "负责人信息不存在");
- }
- $telephone = isset($this->post['telephone']) && $this->post['telephone'] !== "" ? trim($this->post['telephone']) : "";
- $person = isset($to['data']['nickname']) && $to['data']['nickname'] != "" ? $to['data']['nickname'] : "";
- $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
- if ($name == "") {
- return error_show(1002, "数据标题不能为空");
- }
- $is_platform = isset($this->post['is_platform']) && $this->post['is_platform'] !== "" ? intval($this->post['is_platform']) : "0";
- $ticket_type = isset($this->post['ticket_type']) && $this->post['ticket_type'] !== "" ? trim($this->post['ticket_type']) : "";
- $registercode = isset($this->post['registercode']) && $this->post['registercode'] !== "" ? trim($this->post['registercode']) : "";
- $product_category = isset($this->post['product_category']) && $this->post['product_category'] !== "" ? trim($this->post['product_category']) : "";
- $is_payment = isset($this->post['is_payment']) && $this->post['is_payment'] !== "" ? trim($this->post['is_payment']) : "";
- $notice_mark = isset($this->post['notice_mark']) && $this->post['notice_mark'] !== "" ? trim($this->post['notice_mark']) : "";
- $agreement = isset($this->post['agreement']) && $this->post['agreement'] !== "" ? trim($this->post['agreement']) : "";
- $warehouse = isset($this->post['warehouse']) && $this->post['warehouse'] !== "" ? trim($this->post['warehouse']) : "";
- $pay_day = isset($this->post['pay_day']) && $this->post['pay_day'] !== "" ? trim($this->post['pay_day']) : "";
- $supplier_img = isset($this->post['supplier_img']) && $this->post['supplier_img'] !== "" ? trim($this->post['supplier_img']) : "";
- $contactor = isset($this->post['contactor']) && $this->post['contactor'] !== "" ? trim($this->post['contactor']) : "";
- if ($contactor == "") {
- return error_show(1002, "参数contactor不能为空");
- }
- $mobile = isset($this->post['mobile']) && $this->post['mobile'] !== "" ? trim($this->post['mobile']) : "";
- if ($mobile == "") {
- return error_show(1002, "参数mobile不能为空");
- }
- $position = isset($this->post['position']) && $this->post['position'] !== "" ? trim($this->post['position']) : "";
- if ($position == "") {
- return error_show(1002, "参数position不能为空");
- }
- $email = isset($this->post['email']) && $this->post['email'] !== "" ? trim($this->post['email']) : "";
- $data = [
- "id" => $id,
- "source" => $source,
- "name" => $name,
- "coop_state" => $coop_state,
- "category" => $category,
- "delivery_way" => $delivery_way,
- "level" => $level,
- "supplier_type" => $supplier_type,
- "pay_type" => $pay_type,
- "registercode" => $registercode,
- "product_category" => $product_category,
- "is_payment" => $is_payment,
- "notice_mark" => $notice_mark,
- "agreement" => $agreement,
- "warehouse" => $warehouse,
- "pay_day" => $pay_day,
- "type" => $type,
- "license_img" => $supplier_img,
- "is_del" => 0,
-
- "ticket_type" => $ticket_type,
- "updatetime" => date("Y-m-d H:i:s"),
- "is_platform" => $is_platform,
- "prove_img" => $prove_img,
- "person" => $person,
- "personid" => $personid,
- "remark" => "",
- 'updaterid' => $this->uid,
- 'updater' => $this->uname,
- ];
- if ($supplier_img !== "" && $info['data']['license_img'] != $supplier_img) {
- $ocr = new Ocr();
- $dataw = $ocr->query("", $supplier_img);
- if ($dataw['code'] == 0 && isset($dataw['data']['result'])) {
- $license = $dataw['data']['result'];
- $data['legaler'] = isset($license['legal_representative']) ? $license['legal_representative'] : "";
- $data['addr'] = isset($license['address']) ? $license['address'] : "";
- $data['registertime'] = isset($license['found_date']) ? $license['found_date'] : "";
- $data['scope'] = isset($license['business_scope']) ? $license['business_scope'] : "";
- $data['capital'] = isset($license['registered_capital']) ? $license['registered_capital'] : "";
- $data['nature'] = isset($license['type']) ? $license['type'] : "";
- $data['registercode'] = isset($license['registration_number']) ? $license['registration_number'] : "";
- $data['ocr_status'] = 1;
- if ($name != $license['name']) {
- $data['remark'] = "企业名称与营业执照不匹配";
- $data['ocr_status'] = 1;
- }
- if ($registercode != $license['registration_number'] && $registercode != '') {
- $data['remark'] .= "企业名称与营业执照不匹配";
- $data['ocr_status'] = 1;
- }
- } else {
- $data['remark'] = "营业执照识别失败";
- $data['ocr_status'] = 2;
- }
- }
- $temp = [];
- $temp['code'] = $info['data']['code'];
- $temp['contactor'] = $contactor;
- $temp['mobile'] = $mobile;
- $temp['position'] = $position;
- $temp['telephone'] = $telephone;
- $temp['email'] = $email;
- $temp['is_del'] = 0;
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $res = $userCommon->handle('sEdit', ['data' => $data, 'contact' => $temp]);
- Db::startTrans();
- try {
- if ($info['data']['personid'] != $personid) {
- $good = Db::name("good_basic")->where(["supplierNo" => $info['data']['code'], "is_del" => 0])->column('id');
- if (!empty($good)) {
- $up = Db::name("good_basic")->where(["id" => $good])->update(["chargerid" => $personid, "charger" => $person, "updatetime" => date("Y-m-d H:i:s")]);
- if ($up == false) throw new Exception("商品负责人更新失败");
- }
- }
-
- Db::name('warehouse_info')
- ->where(['is_del' => 0, 'supplierNo' => $code['code'], 'wsm_type' => 2])
- ->update(['contactor' => $data['personid'], 'contactor_name' => $data['person']]);
- Db::commit();
- return json_show($res['code'], $res['message'], $res['data']);
- } catch (Exception $exception) {
- Db::rollback();
- return json_show(1004, $exception->getMessage());
- }
- }
- public function info()
- {
- $code = $this->request->only(['code' => ''], 'post', 'trim');
- $userCommon = \app\admin\common\User::getIns();
- $rs = $userCommon->handle('sInfo', $code);
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
-
- public function del()
- {
- $param = $this->request->only(['id' => 0], 'post', 'trim');
- $userCommon = \app\admin\common\User::getIns();
- $rs = $userCommon->handle('delete', [
- 'ids' => [$param['id']],
- 'type' => 3,
- 'updater' => $this->uname,
- 'updaterid' => $this->uid,
- ]);
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
-
- public function status()
- {
- $param = $this->request->only(['id', 'status'], 'post', 'trim');
- $val = Validate::rule([
- 'id' => 'require|number|gt:0',
- 'status|状态' => 'require|number|in:0,1'
- ]);
- if (!$val->check($param)) return json_show(1005, $val->getError());
- $userCommon = \app\admin\common\User::getIns();
- $rs = $userCommon->handle('status', [
- 'id' => $param['id'],
- 'status' => $param['status'],
- 'type' => 3,
- 'updater' => $this->uname,
- 'updaterid' => $this->uid,
- ]);
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
-
- public function upgrade(){
- $param = $this->request->filter('trim')->post();
- $userCommon = \app\admin\common\User::getIns();
- $param['uid']=$this->uid;
- $param['uname']=$this->uname;
- $rs = $userCommon->handle('upgrade', $param);
- if (isset($rs['code']) && $rs['code'] == 0) {
-
- Db::name('user_role')
- ->where(['companyNo' => $param['code'], 'company_type' => 1])
- ->update(['company_type' => 2]);
- }
- return json_show($rs['code'], $rs['message'], $rs['data']);
- }
- }
|