| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- namespace ghs\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\shop\classes\ShopAdminClass;
- 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 bizHd\stat\classes\StatVisitClass;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class CustomController extends BaseController
- {
- //添加新花店 ssh 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'];
- $address = $post['address'] ?? '';
- util::fail('功能已停用');
- 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' => SjClass::STYLE_RETAIL]);
- if (!empty($has)) {
- util::fail('名称已经存在');
- }
- $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
- if (!empty($has)) {
- util::fail('手机号已经添加过');
- }
- if (empty($address)) {
- 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 ?? '';
- $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']);
- //客户欠款额度设置
- $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
- $customId = $custom['id'] ?? 0;
- $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
- CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
- $transaction->commit();
- util::success($custom);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("添加客户没有成功:" . $exception->getMessage());
- util::fail('添加客户没有成功');
- }
- }
- //向队列写入新花店数据 shizhongqi 2022.6.8
- public function actionCreateCustomers()
- {
- $post = Yii::$app->request->post();
- $post['style'] = SjClass::STYLE_RETAIL;
- $sjId = $this->sjId;
- $shopId = $this->shopId;
- for($i = 1; $i <= 5; $i++) {
- $name = $post['name' . $i];
- $mobile = $post['mobile' . $i];
- $confirmMobile = $post['confirmMobile' . $i];
- if (empty($name)) {
- Yii::info("花店名称不能为空");
- continue;
- }
- if (stringUtil::getWordNum($name) > 8) {
- Yii::info('名称不能超过8个汉字');
- continue;
- }
- if (empty($mobile)) {
- Yii::info("手机号不能为空");
- continue;
- }
- if (stringUtil::isMobile($mobile) == false) {
- Yii::info('手机号格式不正确');
- continue;
- }
- if ($mobile != $confirmMobile) {
- Yii::info("添加客户失败:mobile " . $mobile . ' != confirmMobile ' . $confirmMobile);
- continue;
- }
- //队列方式去处理
- $customerCachedKey = 'customers_list';
- $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop['id'] . '_' .$this->shop['shopName'] . '_' . $this->shopAdminId;
- Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
- Yii::info("添加客户:name - " . $name . ' == mobile - ' . $mobile);
- Yii::info("shopAdminId: " . $this->shopAdminId);
- }
- util::complete();
- }
- //客户列表 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 = ['ownMainId' => $this->mainId];
- $sort = 'visitTime DESC';
- if ($type == 1) {
- //消费排行
- $sort = 'buyAmount DESC';
- } else if ($type == 2) {
- //欠款客户
- $where['isDebt'] = 1;
- $sort = 'debtAmount DESC';
- }
- if (!empty($name)) {
- if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- $list = CustomService::getCustomSortList($where, $sort);
- $main = $this->main;
- $list['totalUser'] = $main->totalUser ?? 0;
- $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
- util::success($list);
- }
- //今日访客 ssh 20211022
- public function actionGetVisit()
- {
- $ids = StatVisitClass::getVisitCustomIds($this->shop);
- if (empty($ids)) {
- util::success(['list' => []]);
- }
- $sort = 'visitTime DESC';
- $where = ['id' => ['in', $ids]];
- $respond = CustomService::getCustomSortList($where, $sort);
- util::success($respond);
- }
- //客户详情 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'] = '';
- }
- $mainId = $info['mainId'] ?? 0;
- //超管的信息
- $superInfo = ShopAdminClass::getManager($mainId);
- $superName = $superInfo['name'] ?? '';
- $currentSuper = ['name' => $superName];
- $info['superInfo'] = $currentSuper;
- 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();
- }
- //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
- public function actionSetBlack()
- {
- $black = Yii::$app->request->get('black', 2);
- $customId = Yii::$app->request->get('customId', 0);
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $custom->black = $black;
- $custom->save();
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('出错了');
- }
- $ghs->black = $black;
- $ghs->save();
- 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元
- $main = $this->main;
- $list['customNum'] = $main->mayGatheringNum ?? 0;
- $list['debtAmount'] = $main->mayGathering ?? 0.00;
- util::success($list);
- }
- //修改欠款额度 ssh 20210625
- public function actionUpdateDebtLimit()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('管理员才能操作');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $debtLimit = $get['debtLimit'] ?? 0;
- if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
- util::fail('请填写金额');
- }
- $custom = CustomClass::getById($id, true);
- CustomClass::valid($custom, $this->shopId);
- $custom->debtLimit = $debtLimit;
- $custom->save();
- util::complete();
- }
- //修改折扣 ssh 20210913
- public function actionChangeDiscount()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('管理员才能操作');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $discount = $get['discount'] ?? 0;
- if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
- util::fail('请填写小数值');
- }
- $custom = CustomClass::getById($id, true);
- CustomClass::valid($custom, $this->shopId);
- $custom->discount = $discount;
- $custom->save();
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- $ghs->giveDiscount = $discount;
- $ghs->save();
- util::complete();
- }
- //修改客户等级 ssh 20211007
- public function actionChangeLevel()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能修改');
- }
- $get = Yii::$app->request->get();
- $customId = $get['customId'] ?? 0;
- $level = $get['level'] ?? 1;
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $custom->level = $level;
- $custom->save();
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('出错了');
- }
- $ghs->giveLevel = $level;
- $ghs->save();
- $map = CustomClass::$levelMap;
- $name = $map[$level] ?? '';
- util::success(['levelName' => $name]);
- }
- }
|