| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\sj\classes\SjClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\services\ApplyService;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- class GhsController extends BaseController
- {
- //添加供货商 ssh 20210611
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $mobile = $post['mobile'] ?? '';
- $confirmMobile = $post['confirmMobile'];
- if (stringUtil::isMobile($mobile) == false) {
- util::fail(' 请填写正确的手机号');
- }
- if ($mobile != $confirmMobile) {
- util::fail('二次号码填写不一致');
- }
- $name = $post['name'] ?? '';
- if (empty($name)) {
- util::fail('名称不能为空');
- }
- if (stringUtil::getWordNum($name) > 8) {
- util::fail('名称不能超过8个汉字');
- }
- $has = ApplyClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_KM_SUPPLIER]);
- if (!empty($has)) {
- util::fail('名称已经存在');
- }
- $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_KM_SUPPLIER]);
- if (!empty($has)) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $this->shopId;
- $currentShopId = $has['shopId'] ?? 0;
- if (empty($currentShopId)) {
- util::fail('添加失败');
- }
- $hasGhs = GhsClass::getByCondition(['ownShopId' => $this->shopId, 'shopId' => $currentShopId], true);
- if (!empty($hasGhs)) {
- $name = $hasGhs->name ?? '';
- util::fail("手机已添加过了,供货商名称:【{$name}】");
- }
- $ghs = GhsClass::build($currentShopId, $shopId, 1);
- $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
- $transaction->commit();
- util::success($ghs);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("添加供货商没有成功:" . $exception->getMessage());
- util::fail('添加供货商没有成功');
- }
- util::fail('添加失败,请联系管理员');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $sjId = $this->sjId;
- $shopId = $this->shopId;
- $sjName = $this->sj->name ?? '';
- $address = $post['address'] ?? '';
- $applyData = [
- 'name' => $name,
- 'licenseNo' => $mobile,
- 'certType' => ApplyClass::CERT_TYPE_MOBILE,
- 'mobile' => $mobile,
- 'introSjId' => $sjId,
- 'introSjName' => $sjName,
- 'introShopId' => $shopId,
- 'introStyle' => SjClass::STYLE_SUPPLIER,
- 'from' => ApplyClass::FROM_GHS,
- 'style' => dict::getDict('ptStyle', 'kmGhs'),
- 'address' => $address,
- 'status' => ApplyClass::STATUS_PASS,
- ];
- $apply = ApplyService::replaceKmGhs($applyData);
- $id = $apply['id'] ?? 0;
- $respond = \bizJd\apply\services\ApplyService::pass($id);
- $shop = $respond['shop'] ?? [];
- $sj = $respond['sj'] ?? [];
- $currentSjId = $sj['id'] ?? 0;
- $currentShopId = $shop->id ?? 0;
- ApplyClass::updateById($id, ['sjId' => $currentSjId, 'shopId' => $currentShopId]);
- if (empty($currentShopId)) {
- util::fail('供货商没有添加成功!');
- }
- $ghs = GhsClass::build($currentShopId, $shopId, 1);
- $ghs['avatar'] = imgUtil::groupImg($ghs['avatar']);
- $transaction->commit();
- util::success($ghs);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("添加供货商没有成功:" . $exception->getMessage());
- util::fail('添加供货商没有成功');
- }
- }
- //供货商列表 ssh 2021.1.18
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
- $where = ['ownShopId' => $this->shopId];
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $list = GhsClass::getGhsList($where);
- util::success($list);
- }
- }
|