| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <?php
- namespace ghs\controllers;
- use biz\admin\classes\AdminRoleClass;
- 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 bizGhs\order\classes\OrderClass;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\services\ApplyService;
- use bizHd\shop\classes\ShopClass;
- use bizHd\stat\classes\StatVisitClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class CustomController extends BaseController
- {
- //修改名称 ssh 2022096
- public function actionChangeName()
- {
- $get = Yii::$app->request->get();
- $name = $get['name'] ?? '';
- $id = $get['id'] ?? 0;
- if (empty($name)) {
- util::fail('请填写名称');
- }
- $py = stringUtil::py($name);
- $custom = CustomClass::getById($id, true);
- CustomClass::valid($custom, $this->shopId);
- $custom->name = $name;
- $custom->py = $py;
- $custom->save();
- OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
- $customShopId = $custom->shopId ?? 0;
- //在首店修改客户名称,直营店自动同步
- $masterShop = $this->shop;
- if (isset($masterShop->default) && $masterShop->default == 1) {
- $sjId = $masterShop->sjId ?? 0;
- $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
- foreach ($shopList as $shop) {
- $shopId = $shop->id ?? 0;
- if (isset($shop->join) && $shop->join == 1) {
- //加盟店不同步修改
- continue;
- }
- if ($shopId == $masterShop->id) {
- //前面已经同步修改过了
- continue;
- }
- $custom = CustomClass::getByCondition(['ownShopId' => $shopId, 'shopId' => $customShopId], true);
- if (empty($custom)) {
- continue;
- }
- $custom->name = $name;
- $custom->py = $py;
- $custom->save();
- }
- }
- util::complete('修改成功');
- }
- //帮客户添加员工 ssh 20220613
- public function actionAddStaff()
- {
- $post = Yii::$app->request->post();
- $customId = $post['id'] ?? 0;
- $mobile = $post['mobile'] ?? 0;
- if (stringUtil::isMobile($mobile) == false) {
- util::fail('手机号填写错误');
- }
- $info = CustomService::getById($customId, true);
- CustomClass::valid($info, $this->shopId);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $info->shopId ?? 0;
- $customShop = ShopClass::getById($shopId, true);
- if (empty($customShop)) {
- util::fail('没有找到客户的门店');
- }
- $mainId = $customShop->mainId ?? 0;
- $ptStyle = dict::getDict('ptStyle', 'hd');
- $adminInfo = ['name' => $mobile, 'mobile' => $mobile, 'style' => $ptStyle, 'currentShopId' => $shopId];
- $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
- $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
- $roleList = AdminRoleClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (empty($roleList)) {
- util::fail('客户门店没有员工角色');
- }
- $currentRoleId = 0;
- foreach ($roleList as $role) {
- $roleId = $role->id ?? 0;
- $currentRoleId = $roleId;
- if ($role->roleName == '员工') {
- break;
- }
- }
- $params = [
- 'shopId' => $shopId,
- 'mobile' => $mobile,
- 'roleId' => $currentRoleId,
- ];
- \bizHd\staff\classes\StaffClass::appGenerateStaff($params, $admin);
- $transaction->commit();
- util::complete('添加成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- util::fail('添加失败');
- }
- }
- //添加新花店 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();
- $arr = [];
- for ($i = 1; $i <= 5; $i++) {
- $name = $post['name' . $i] ?? '';
- $mobile = $post['mobile' . $i] ?? '';
- $confirmMobile = $post['confirmMobile' . $i] ?? '';
- if (empty($name) && empty($mobile) && empty($confirmMobile)) {
- continue;
- }
- if (empty($name)) {
- util::fail('花店名称不能为空');
- }
- $has = SjClass::getByCondition(['name' => $name]);
- if (!empty($has)) {
- //util::fail($name . ' 这个名称已经被别人使用了');
- }
- if (stringUtil::getWordNum($name) > 8) {
- util::fail('名称不能超过8个汉字');
- }
- if (empty($mobile)) {
- util::fail($name . " 手机号不能为空");
- }
- if (stringUtil::isMobile($mobile) == false) {
- util::fail($name . " 手机号格式不正确");
- }
- if ($mobile != $confirmMobile) {
- util::fail($name . " 二次手机号不一致");
- }
- $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
- if (!empty($hasShop)) {
- $shop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => 1], true);
- if (!empty($shop)) {
- $ghsShopId = $this->shopId;
- $hdShopId = $shop->id;
- CustomClass::build($ghsShopId, $hdShopId);
- util::complete($shop->merchantName . ' 添加成功');
- }
- util::fail($mobile . "手机号已经添加过了");
- }
- $has = ApplyClass::getByCondition(['mobile' => $mobile]);
- if (!empty($has)) {
- util::fail($mobile . "手机号已经申请添加过了");
- }
- $arr[] = ['name' => $name, 'mobile' => $mobile];
- }
- if (empty($arr)) {
- util::fail('请填写客户');
- }
- foreach ($arr as $item) {
- $name = $item['name'] ?? '';
- $mobile = $item['mobile'] ?? '';
- //队列方式去处理
- $customerCachedKey = 'batch_create_customer_list';
- $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop->id . '_' . $this->sj->name . '_' . $this->shopAdminId;
- Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
- Yii::info("供货商添加客户:name - " . $name . ' == mobile - ' . $mobile);
- Yii::info("shopAdminId: " . $this->shopAdminId);
- }
- util::complete('已添加,1分钟后生效');
- }
- //从其它店同步客户 shizhongqi 2022.6.9
- public function actionCopyCustomers()
- {
- $get = Yii::$app->request->get();
- $fromShopId = $get['fromShopId'] ?? 0;
- $fromShop = ShopClass::getById($fromShopId, true);
- if (empty($fromShop)) {
- util::fail('门店不存在');
- }
- $toShopId = $this->shopId;
- if ($fromShopId == $toShopId) {
- util::fail('本店无需同步');
- }
- $toShop = $this->shop;
- $toSjId = $toShop->sjId ?? 0;
- $fromSjId = $fromShop->sjId ?? 0;
- if ($toSjId != $fromSjId) {
- util::fail('不是您的门店');
- }
- $cachedKey = 'copy_other_shop_customers';
- Yii::$app->redis->executeCommand('LPUSH', [$cachedKey, $toShopId . '_' . $fromShopId]);
- Yii::info("从其他门店同步客户:目标门店id = " . $toShopId . ' 来源门店id = ' . $fromShopId);
- util::complete('已提交,1分钟后生效');
- }
- //客户列表 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]);
- }
- }
|