|
|
@@ -3,6 +3,10 @@
|
|
|
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\imgUtil;
|
|
|
use common\components\stringUtil;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
@@ -10,14 +14,75 @@ use common\components\util;
|
|
|
class GhsController extends BaseController
|
|
|
{
|
|
|
|
|
|
+ //添加供货商 shish 20210611
|
|
|
public function actionAdd()
|
|
|
{
|
|
|
- $data = [
|
|
|
- 'id' => 2,
|
|
|
- 'name' => '小石头',
|
|
|
- 'avatar' => 'https://img.hzghd.com/ghs/home/deserve.png',
|
|
|
- ];
|
|
|
- util::success($data);
|
|
|
+ $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)) {
|
|
|
+ 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' => SjClass::STYLE_KM_SUPPLIER,
|
|
|
+ 'address' => $address,
|
|
|
+ 'status' => ApplyClass::STATUS_PASS,
|
|
|
+ 'replace' => 1,//1表示供货商添加的客户或供货商
|
|
|
+ ];
|
|
|
+ $apply = ApplyService::replaceKmGhs($applyData);
|
|
|
+ $id = $apply['id'] ?? 0;
|
|
|
+ $respond = 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
|