| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace ghs\controllers;
- use biz\sj\classes\SjClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\custom\services\CustomService;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\services\ApplyService;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class CustomController extends BaseController
- {
- //添加新花店 shish 2021.1.8
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['style'] = SjClass::STYLE_RETAIL;
- $post['introSjId'] = $this->sjId;
- $post['introStyle'] = SjClass::STYLE_SUPPLIER;
- $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 = SjClass::getByCondition(['name' => $name, 'style' => ApplyClass::FROM_GHS]);
- if (!empty($has)) {
- util::fail('名称已经存在');
- }
- $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => ApplyClass::FROM_GHS]);
- if (!empty($has)) {
- util::fail('手机号已经添加过');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- $sjId = $this->sjId;
- $shopId = $this->shopId;
- $sjName = $this->sj->name ?? '';
- $city = $shop->city ?? '';
- $dist = $shop->dist ?? '';
- $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_RETAIL,
- 'province' => $shop->province ?? '',
- 'city' => $city,
- 'dist' => $dist,
- 'address' => $address,
- 'status' => ApplyClass::STATUS_PASS,
- 'replace' => 1,//1表示供应商添加的客户
- ];
- $apply = ApplyService::replaceRetail($applyData);
- $id = $apply['id'] ?? 0;
- $respond = ApplyService::pass($id);
- $shop = $respond['shop'] ?? [];
- $sj = $respond['sj'] ?? [];
- $hdSjId = $sj['id'] ?? 0;
- $hdShopId = $shop->id ?? 0;
- ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
- if (empty($hdShopId)) {
- util::fail('客户没有添加成功!');
- }
- $custom = CustomClass::build($this->shopId, $hdShopId);
- $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
- $transaction->commit();
- util::success($custom);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("添加客户没有成功:" . $exception->getMessage());
- util::fail('添加客户没有成功');
- }
- }
- //客户列表 ssh 2021.7.8
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $type = isset($get['type']) ? $get['type'] : 0;
- $name = isset($get['name']) ? $get['name'] : '';
- $where = ['ownShopId' => $this->shopId];
- switch ($type) {
- case 1:
- //已开店
- $where['isOpen'] = 1;
- break;
- default:
- }
- if (!empty($name)) {
- if (stringUtil::isMobile($name)) {
- $where['mobile'] = $name;
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $list = CustomService::getCustomList($where);
- util::success($list);
- }
- //客户详情 ssh 2021.1.8
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $customId = $get['id'] ?? 0;
- $info = CustomService::getCustomInfo($customId);
- CustomClass::valid($info, $this->shopId);
- //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
- if (isset($info['lat']) && empty($info['lat'])) {
- $info['address'] = '';
- }
- if (isset($info['long']) && empty($info['long'])) {
- $info['address'] = '';
- }
- util::success($info);
- }
- //允许月结开关 ssh 2021.1.8
- public function actionDebt()
- {
- $get = Yii::$app->request->get();
- $debt = isset($get['debt']) ? $get['debt'] : 0;
- $customId = isset($get['customId']) ? $get['customId'] : 0;
- $custom = CustomClass::getById($customId);
- CustomClass::valid($custom, $this->shopId);
- CustomClass::debt($custom, $debt);
- util::complete();
- }
- //欠款客户 ssh 2021.2.4
- public function actionDebtList()
- {
- $get = Yii::$app->request->get();
- $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
- if (isset($get['name']) && !empty($get['name'])) {
- $where['name'] = ['like', $get['name']];
- }
- $list = CustomService::getDebtList($where);
- //共X个客户,合计欠款XXX元
- $shop = $this->shop;
- $list['customNum'] = $shop->mayGatheringNum ?? 0;
- $list['debtAmount'] = $shop->mayGathering ?? 0.00;
- util::success($list);
- }
- }
|