| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198 |
- <?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 biz\wx\classes\WxMessageClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\custom\services\CustomService;
- use common\components\noticeUtil;
- use common\components\qrCodeUtil;
- 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 bizGhs\stat\classes\StatVisitClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\orderSn;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class CustomController extends BaseController
- {
- //批量设置是否可看库存 ssh 20251031
- public function actionAllSetLookStock()
- {
- $get = Yii::$app->request->get();
- $showStock = $get['showStock'] ?? 0;
- $mainId = $this->mainId;
- CustomClass::updateByCondition(['ownMainId' => $mainId], ['showStock' => $showStock]);
- \bizGhs\ghs\classes\GhsClass::updateByCondition(['mainId' => $mainId], ['showStock' => $showStock]);
- util::complete('设置成功');
- }
- //批量设置是否可看销量 ssh 20251031
- public function actionAllSetLookSale()
- {
- $get = Yii::$app->request->get();
- $showSold = $get['showSold'] ?? 0;
- $shop = $this->shop;
- //没有配置到每个客户,只在总店有控制
- $shop->showSold = $showSold;
- $shop->save();
- util::complete('设置成功');
- }
- //批量授信 ssh 20251031
- public function actionAllCredit()
- {
- $staff = $this->shopAdmin;
- if ($staff->mobile != 15280215347) {
- util::fail('请管理员操作');
- }
- $get = Yii::$app->request->get();
- $amount = $get['amount'] ?? 0;
- $mainId = $this->mainId;
- CustomClass::updateByCondition(['ownMainId' => $mainId], ['debtLimit' => $amount]);
- util::complete('设置成功');
- }
- //客户设置相关 ssh 20250310
- public function actionSetChange()
- {
- $staff = $this->shopAdmin;
- if ($staff->founder != 2 && $staff->mobile != 15280215347) {
- util::fail('老板才能修改');
- }
- $post['homeAmount'] = !empty($post['homeAmount']) && is_numeric($post['homeAmount']) ? $post['homeAmount'] : 0;
- $post = Yii::$app->request->post();
- $shopId = $this->shopId;
- ShopClass::updateById($shopId, $post);
- $showStock = $post['showStock'] ?? 0;
- $arr = ['showStock' => $showStock];
- //如果新客需要审核,老的全部要打开为已经审核通过了
- $arr['passStatus'] = 1;
- CustomClass::updateByCondition(['ownShopId' => $shopId], $arr);
- GhsClass::updateByCondition(['shopId' => $shopId], $arr);
- util::complete('修改成功');
- }
- //获取收款码 ssh 20240530
- public function actionGetGatheringCode()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $custom = CustomClass::getById($id, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户哈');
- }
- $ghsId = $custom->ghsId ?? 0;
- $salt = $custom->salt ?? '';
- //有多个地方要同步修改,关键词 custom_go_ghs_gathering_code
- if (getenv('YII_ENV') == 'production') {
- $url = "https://mall.huahb.cn/#/admin/ghs/pay?id={$ghsId}&salt={$salt}";
- } else {
- $url = "https://mall.huaml.com/#/admin/ghs/pay?id={$ghsId}&salt={$salt}";
- }
- $unique = "recharge_to_ghs_" . $id;
- $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
- $imageUrl = imgUtil::groupImg($imgUrl);
- util::success(['imgUrl' => $imageUrl]);
- }
- //供货商给客户充值和结账 ssh 20240309
- public function actionRecharge()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- //避免重复提交
- $staffId = $this->shopAdminId;
- util::checkRepeatCommit($staffId, 5);
- $staff = $this->shopAdmin;
- if (isset($staff->finance) == false || $staff->finance == 0) {
- if ($this->shopId == 17118) {
- //淘花里中山店,没有财务权限要能销账
- if (!in_array($this->adminId, [17908])) {
- util::fail('你不能充值销账哦');
- }
- } elseif ($this->shopId == 72366) {
- //淘花里小榄店,没有财务权限要能销账
- if (!in_array($this->adminId, [69792])) {
- util::fail('你不能充值销账哦');
- }
- } else {
- util::fail('无法充值销单。。。');
- }
- }
- //多个地方需要同步修改clear_order_power
- if (getenv('YII_ENV') == 'production') {
- //小向花卉
- if (in_array($this->shopId, [23580, 24713])) {
- if (!in_array($this->adminId, [24043, 23960, 4])) {
- util::fail('不能销单哦!!');
- }
- }
- //花样年华只有总控才能结账
- if (in_array($this->shopId, [1585, 1596])) {
- if ($this->adminId != 2876) {
- util::fail('不能充值销单哦');
- }
- }
- //花大苪 洋桔梗,只有叶荷姐才能销账
- if (in_array($this->shopId, [16070])) {
- if (!in_array($this->adminId, [9303, 4])) {
- util::fail('不能充值销单哈');
- }
- }
- //恋善好多花控制销账权限
- if (in_array($this->shopId, [55238, 56609, 56611])) {
- if (!in_array($this->adminId, [43856, 54620])) {
- util::fail('暂无权限销单,请联系老板或财务');
- }
- }
- //天天鲜花 陈江店
- if (in_array($this->shopId, [763, 1405, 795])) {
- if (!in_array($this->adminId, [2094, 5959])) {
- util::fail('不能操作充值销单!');
- }
- }
- //花儿好仙
- if (in_array($this->shopId, [22666])) {
- if (!in_array($this->adminId, [12869, 23174])) {
- util::fail('不能充值销单哈');
- }
- }
- //小丽鲜花
- if (in_array($this->shopId, [11094])) {
- if (!in_array($this->adminId, [12073, 12296])) {
- util::fail('您不能充值销单哦');
- }
- }
- //源花汇
- if (in_array($this->shopId, [10649])) {
- if (!in_array($this->adminId, [11641, 11648, 4])) {
- util::fail('请闵总或小周操作');
- }
- }
- //昱成
- if (in_array($this->shopId, [8596])) {
- if (!in_array($this->adminId, [9303, 9601])) {
- util::fail('只能叶荷操作');
- }
- }
- //花大苪,多处请搜索关键词 hdb_clear_control
- if (in_array($this->shopId, [8249])) {
- if (!in_array($this->adminId, [9303])) {
- util::fail('只能叶荷和财务操作');
- }
- }
- //中山淘花里,销账权限控制,多处请搜索 thl_clear_control
- if (in_array($this->shopId, [17118])) {
- if (!in_array($this->adminId, [55494, 55445, 17908, 55459, 55707, 55709])) {
- util::fail('你不能销单哈。。');
- }
- }
- //淘花里小榄店 thl_xl_clear
- if (in_array($this->shopId, [72366])) {
- if (!in_array($this->adminId, [69792, 55445, 55707, 69792])) {
- util::fail('你不能销单那,编号1956');
- }
- }
- //淘花里珠海店
- if (in_array($this->shopId, [78556])) {
- if (!in_array($this->adminId, [69132, 75771, 43732, 55734, 47775, 55711, 40678, 75798])) {
- util::fail('你不能销单哦,编号88831');
- }
- }
- //小齐鲜花总店和出车,多处请搜索关键词 xq_clear_control
- if (in_array($this->shopId, [41467, 42946])) {
- if (!in_array($this->adminId, [40144, 42912, 42023])) {
- util::fail('您不能充值销单哦,编号956');
- }
- }
- } else {
- if (in_array($this->shopId, [36523])) {
- if ($this->adminId != 919) {
- util::fail('暂不能操作充值销单哈');
- }
- }
- }
- $get = Yii::$app->request->get();
- $amount = $get['amount'] ?? 0;
- $customId = $get['customId'] ?? 0;
- $payWay = $get['payWay'] ?? -1;
- $remark = $get['remark'] ?? '';
- $rechargeType = $get['rechargeType'] ?? 0;
- if ($rechargeType == 0 && $payWay < 0) {
- util::fail('请选择付款方式');
- }
- if ($amount <= 0) {
- //util::fail('充值金额需要大于0');
- }
- //解决重复充值问题
- $cacheKey = 'help_custom_recharge_' . $customId;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('已充值,请15秒后再操作');
- return false;
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 15, 'has']);
- $custom = CustomClass::getLockById($customId);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户,无法充值');
- }
- $customShopId = $custom->shopId ?? 0;
- $shop = $this->shop;
- if ($customShopId == $shop->lsShopId) {
- util::fail('不能给自己充值');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $staff = $this->shopAdmin;
- $params = ['remark' => $remark, 'rechargeType' => $rechargeType];
- $recharge = CustomService::rechargeClear($custom, $amount, $this->shop, $staff, $payWay, $params);
- $transaction->commit();
- WxMessageClass::customRechargeClearInform($shop, $recharge);
- util::complete('充值成功');
- } catch (\Exception $e) {
- Yii::info("充值失败原因:" . $e->getMessage());
- $transaction->rollBack();
- util::fail('充值失败');
- }
- }
- //生成货位号 ssh 20231215
- public function actionCreateSeatSn()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $custom = CustomClass::getById($id, true);
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是您的客户');
- }
- $seatSn = $custom->seatSn ?? '';
- if (!empty($seatSn)) {
- util::fail('已经有货位号了');
- }
- $new = CustomClass::createSeatSn($this->mainId);
- $custom->seatSn = $new;
- $custom->save();
- //预订相关表的货位同步
- $shop = $this->shop;
- CustomClass::syncBookSeat($shop, $custom, $new);
- util::complete('已生成');
- }
- //修改货位号 ssh 20231215
- public function actionModifySeatSn()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $new = $get['seatSn'] ?? 0;
- $custom = CustomClass::getById($id, true);
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是您的客户');
- }
- if (is_numeric($new) == false) {
- util::fail('请填写数字');
- }
- $custom->seatSn = $new;
- $custom->save();
- //预订相关表的货位同步
- $shop = $this->shop;
- CustomClass::syncBookSeat($shop, $custom, $new);
- util::complete('修改成功');
- }
- //修改客户地址 ssh 20230929
- public function actionModifyAddress()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- unset($post['id']);
- $custom = CustomClass::getById($id, true);
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是您的客户哦');
- }
- $city = $post['city'] ?? '';
- $dist = $post['dist'] ?? '';
- $address = $post['address'] ?? '';
- $floor = $post['floor'] ?? '';
- $post['fullAddress'] = $city . $dist . $address . $floor;
- $shopId = $custom->shopId ?? 0;
- ShopClass::updateById($shopId, $post);
- CustomClass::updateByCondition(['shopId' => $shopId], $post);
- util::complete('修改成功');
- }
- //修改花店散客身份 ssh 20230216
- public function actionChangeIsHd()
- {
- $get = Yii::$app->request->get();
- $id = $get['customId'] ?? 0;
- $isHd = $get['isHd'] ?? 1;
- $custom = CustomClass::getById($id, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('没有权限');
- }
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('修改失败了');
- }
- $ghs->isHd = $isHd;
- $ghs->save();
- $custom->isHd = $isHd;
- $custom->save();
- util::complete('修改成功');
- }
- //修改物流名称 ssh 20230112
- public function actionChangeWlName()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $wlName = $get['wlName'] ?? 0;
- $custom = CustomClass::getById($id, true);
- if (empty($custom) || $custom->ownMainId != $this->mainId) {
- util::fail('修改失败');
- }
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('修改失败');
- }
- $ghs->customWlName = $wlName;
- $ghs->save();
- $custom->wlName = $wlName;
- $custom->save();
- util::complete('已修改');
- }
- //修改短名 ssh 2025312
- public function actionModifyShortName()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $shortName = $get['shortName'] ?? 0;
- $custom = CustomClass::getById($id, true);
- if (empty($custom) || $custom->ownMainId != $this->mainId) {
- util::fail('修改失败');
- }
- $custom->shortName = $shortName;
- $custom->save();
- util::complete('修改成功');
- }
- //修改物流信息 ssh 20230105
- public function actionChangeWl()
- {
- util::fail('修改失败');
- }
- //修改名称 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) > 15) {
- util::fail('名称不能超过15个汉字');
- }
- $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'] : 0;
- 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();
- $virtual = $post['virtual'] ?? 0;
- $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('花店名称不能为空');
- }
- if (stringUtil::getWordNum($name) > 15) {
- util::fail('名称不能超过15个汉字');
- }
- if (empty($mobile)) {
- //添加虚拟客户
- if ($virtual == 1) {
- $mobile = orderSn::getMobileSn();
- $confirmMobile = $mobile;
- } else {
- 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;
- $custom = CustomClass::build($ghsShopId, $hdShopId);
- $customId = $custom['id'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (!empty($custom)) {
- $custom->name = $name;
- $py = stringUtil::py($name);
- $custom->py = $py;
- $custom->save();
- }
- util::success(['customId' => $customId], $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'] ?? '';
- //使用消息队列处理
- try {
- $producer = Yii::$app->rabbitmq->getProducer('customProducer');
- $msg = serialize(['type' => 'add_custom', 'name' => $name, 'mobile' => $mobile, 'sjId' => $this->sjId,
- 'shopId' => $this->shop->id, 'sjName' => $this->sj->name, 'staffId' => $this->shopAdminId]);
- $producer->publish($msg, 'customExchange', 'customRoute',['delivery_mode' => 2, 'content_type' => 'application/octet-stream']);
- } catch (\Exception $e) {
- $msg = $e->getMessage();
- $remind = "供货商创建新客户,生产消息报错 {$name} {$mobile} {$this->sj->name} {$msg}";
- noticeUtil::push($remind, '15280215347');
- }
- }
- util::complete('已添加');
- }
- //从其它店同步客户 shizhongqi 2022.6.9
- public function actionCopyCustomers()
- {
- //限制请求次数
- $shopId = $this->shopId;
- util::perDayCommitTimeLimit($shopId, 3);
- //限制频繁请求
- util::checkRepeatCommit($this->adminId, 6);
- $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('本店无需同步');
- }
- $fromShopName = $fromShop->shopName ?? '';
- if ($fromShop->syncCustom == 0) {
- util::fail('不允许从' . $fromShopName . '同步客户');
- }
- $toShop = $this->shop;
- $toShopName = $toShop->shopName ?? '';
- if ($toShop->syncCustom == 0) {
- util::fail($toShopName . '已关闭同步功能');
- }
- $toSjId = $toShop->sjId ?? 0;
- $fromSjId = $fromShop->sjId ?? 0;
- if ($toSjId != $fromSjId) {
- util::fail('不是您的门店');
- }
- //使用消息队列处理 ssh 20251204
- try {
- $producer = Yii::$app->rabbitmq->getProducer('customProducer');
- $msg = serialize(['type' => 'pull_custom_from_other_shop', 'toShopId' => $toShopId, 'fromShopId' => $fromShopId]);
- $producer->publish($msg, 'customExchange', 'customRoute',['delivery_mode' => 2, 'content_type' => 'application/octet-stream']);
- } catch (\Exception $e) {
- $msg = $e->getMessage();
- $remind = "供货商拉取其他门店客户,生产消息报错 {$toShopId} {$fromShopId} {$msg}";
- noticeUtil::push($remind, '15280215347');
- }
- util::complete('已拉取');
- }
- //客户列表 ssh 2021.7.8
- public function actionList()
- {
- $staff = $this->shopAdmin;
- if (isset($staff->identity) && $staff->identity == 2) {
- util::success(['list' => []]);
- }
- $get = Yii::$app->request->get();
- $type = $get['type'] ?? 0;
- $name = $get['name'] ?? '';
- $export = $get['export'] ?? 0;
- $mainId = $this->mainId;
- $isCashier = $get['isCashier'] ?? 0;
- if ($isCashier == 1) {
- //去掉收银台提示价格更新
- $staffId = $this->shopAdminId;
- Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
- }
- $where = ['ownMainId' => $this->mainId];
- $sort = 'visitTime DESC';
- $where['delStatus'] = 0;
- if ($type == 1) {
- //消费排行
- $sort = 'buyAmount DESC';
- } else if ($type == 2) {
- //欠款客户
- $where['isDebt'] = 1;
- $sort = '(debtAmount-balance) DESC';
- } else if ($type == 3) {
- //大客户
- $where['level'] = 2;
- } else if ($type == 4) {
- //零售客户
- $where['level'] = 0;
- } else if ($type == 5) {
- //休眠客户
- $recentDay = isset($get['recentDay']) && is_numeric($get['recentDay']) ? (int)$get['recentDay'] : 30;
- $totalSecond = bcmul(86400, $recentDay);
- $currentSecond = bcsub(time(), $totalSecond);
- $currentDate = date("Y-m-d H:i:s", $currentSecond);
- $where['recentExpend<'] = $currentDate;
- $sort = 'recentExpend desc';
- } else if ($type == 6) {
- //黑名单
- $where['black'] = 2;
- } else if ($type == 7) {
- //已删除
- $where['delStatus'] = 1;
- }
- $name = trim($name);
- if (!empty($name)) {
- if (is_numeric($name)) {
- if (stringUtil::isMobile($name)) {
- $where['mobile'] = $name;
- } else {
- $shop = $this->shop;
- //如果花大苪,搜索数字还是优先搜索客户名称,因为客户名称经常会编号
- if ($shop->id == 8249) {
- $where['name'] = ['like', $name];
- } else {
- $where['mobile'] = ['like', $name];
- }
- }
- } else if (stringUtil::isLetter($name)) {
- $where['py'] = ['like', $name];
- } else {
- $where['name'] = ['like', $name];
- }
- }
- if ($export == 1) {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- CustomClass::exportCustom($where, $sort, $this->mainId);
- util::stop();
- }
- $list = CustomService::getCustomSortList($where, $sort);
- $main = $this->main;
- $list['totalUser'] = $main->totalUser ?? 0;
- $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
- $list['shopInfo'] = $this->shop;
- 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);
- $mainId = $info['mainId'] ?? 0;
- //超管的信息
- $superInfo = ShopAdminClass::getManager($mainId);
- $superName = $superInfo['name'] ?? '';
- $currentSuper = ['name' => $superName];
- $info['superInfo'] = $currentSuper;
- util::success($info);
- }
- //修改是否显示库存 ssh 20221022
- public function actionChangeShowStock()
- {
- $get = Yii::$app->request->get();
- $showStock = $get['showStock'] ?? 0;
- $customId = $get['customId'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $ghs->showStock = $showStock;
- $ghs->save();
- $custom->showStock = $showStock;
- $custom->save();
- util::complete();
- }
- //修改状态 ssh 20240924
- public function actionChangePassStatus()
- {
- $get = Yii::$app->request->get();
- $passStatus = isset($get['passStatus']) ? $get['passStatus'] : 0;
- $customId = isset($get['customId']) ? $get['customId'] : 0;
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $ghs->passStatus = $passStatus;
- $ghs->save();
- $custom->passStatus = $passStatus;
- $custom->save();
- util::complete();
- }
- public function actionChangeHome()
- {
- $get = Yii::$app->request->get();
- $home = isset($get['home']) ? $get['home'] : 0;
- $customId = !empty($get['customId']) ? $get['customId'] : 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户呢');
- }
- if ($custom->ownShopId != $this->shopId) {
- util::fail('不是你的客户');
- }
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $ghs->home = $home;
- $ghs->save();
- $custom->home = $home;
- $custom->save();
- util::complete();
- }
- /**
- * 上门最低消费设置 -- 单个修改
- */
- public function actionModifyHomeAmount()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $homeAmount = $get['homeAmount'] ?? 0;
- $homeType = $get['homeType'] ?? 0;
- $custom = CustomClass::getById($id, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->ownMainId != $this->mainId) {
- util::fail('不是你的客户');
- }
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('没有找到供货商');
- }
- $custom->homeAmount = $homeAmount;
- $custom->homeType = $homeType;
- $custom->save();
- $ghs->homeAmount = $homeAmount;
- $ghs->homeType = $homeType;
- $ghs->save();
- util::complete('修改成功');
- }
- /**
- * 上门最低消费设置 -- 针对批发商客户进行批量修改
- */
- public function actionModifyAllHomeAmount()
- {
- $get = Yii::$app->request->get();
- $homeAmount = $get['homeAmount'] ?? 0;
- $homeType = $get['homeType'] ?? 0;
- $shopId = $this->shopId;
- ShopClass::updateById($shopId, ['homeAmount' => $homeAmount, 'homeType' => $homeType]);
- // 批量更新客户信息
- CustomClass::updateByCondition(['ownMainId' => $this->mainId], ['homeAmount' => $homeAmount, 'homeType' => $homeType]);
- //批量更新供货商信息
- GhsClass::updateByCondition(['shopId' => $shopId], ['homeAmount' => $homeAmount, 'homeType' => $homeType]);
- util::complete('修改成功');
- }
- //允许月结开关 ssh 2021.1.8
- public function actionDebt()
- {
- if (getenv('YII_ENV') == 'production') {
- if ($this->mainId == 4884) {
- if ($this->shopAdminId != 130738) {
- util::fail('只有倩姐才能修改');
- }
- }
- }
- $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('管理员才能操作');
- }
- if (getenv('YII_ENV') == 'production') {
- if ($this->mainId == 4884) {
- if ($this->shopAdminId != 130738) {
- util::fail('请倩姐修改');
- }
- }
- if ($this->mainId == 10536) {
- if ($this->shopAdminId != 136416 && $this->shopAdminId != 136419) {
- 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 20241006
- public function actionUpdateSeatSnName()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $seatSnName = $get['seatSnName'] ?? '';
- $custom = CustomClass::getById($id, true);
- CustomClass::valid($custom, $this->shopId);
- $custom->seatSnName = $seatSnName;
- $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('超管才能修改');
- }
- //泉城的只有苏小娟才能修改
- if (getenv('YII_ENV') == 'production') {
- if ($this->mainId == 60) {
- if (in_array($this->adminId, [2499, 4]) == false) {
- 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]);
- }
- //打印货位号 ssh 20241006
- public function actionPrintSeatSn()
- {
- $get = Yii::$app->request->get();
- $customId = $get['id'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $seatSn = $custom->seatSn ?? 0;
- if ($seatSn == 0) {
- util::fail('没有货位');
- }
- $customName = $custom->name ?? '';
- if (isset($custom->seatSnName) && !empty($custom->seatSnName)) {
- $customName = $custom->seatSnName ?? '';
- }
- $customName = stringUtil::subStringUtf8($customName, 7, '..');
- $a4Print = [
- 'customName' => $customName,
- 'seatSn' => $seatSn,
- ];
- $info['printData'] = $a4Print;
- $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":45,"top":52.5,"height":52,"width":128,"title":"文本","right":172.25,"bottom":104.5,"vCenter":108.25,"hCenter":78.5,"field":"seatSn","testData":"593","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":50,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":148.5,"top":52.5,"height":52,"width":400,"title":"文本","field":"customName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":50,"fontWeight":"bolder","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":566.5,"bottom":90.25,"vCenter":366.5,"hCenter":71.75},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":547.5,"paperNumberTop":786,"paperNumberDisabled":true,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
- $info['template'] = $template;
- $custom->printSeatSn = 1;
- $custom->save();
- util::success($info);
- }
- //总赊账和总余额汇总 ssh 20250620
- public function actionShowTotalBalance()
- {
- $lookMoney = \bizGhs\shop\classes\ShopAdminClass::lookMoneyPower($this->shopAdmin, $this->shop);
- if ($lookMoney == 0) {
- util::fail('无法查看哦');
- }
- $pfShop = $this->shop;
- $lsShopId = $pfShop->lsShopId;
- $pfShopId = $this->shopId;
- $respond = CustomClass::showTotalBalance($pfShopId, $lsShopId);
- $respond['pfShopId'] = $pfShopId;
- $respond['lsShopId'] = $lsShopId;
- util::success($respond);
- }
- public function actionChangeDelStatus()
- {
- $get = Yii::$app->request->get();
- $customId = $get['id'] ?? 0;
- $delStatus = $get['delStatus'] ?? 0;
- $custom = CustomClass::getById($customId, true);
- CustomClass::valid($custom, $this->shopId);
- $ghsId = $custom->ghsId ?? 0;
- $ghs = GhsClass::getById($ghsId, true);
- if (empty($ghs)) {
- util::fail('客户信息有缺失');
- }
- $custom->delStatus = $delStatus;
- $custom->save();
- $ghs->delStatus = $delStatus;
- $ghs->save();
- util::complete('删除成功');
- }
- }
|