| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046 |
- <?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 bizGhs\merchant\classes\WlClass;
- 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 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 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) {
- 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('你不能销单哈。。');
- }
- }
- //小齐鲜花总店和出车,多处请搜索关键词 xq_clear_control
- if (in_array($this->shopId, [41467, 42946])) {
- if (!in_array($this->adminId, [40144, 42912, 42023])) {
- util::fail('您不能充值销单哦。');
- }
- }
- } 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'] : 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();
- $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'] ?? '';
- //队列方式去处理
- $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('已提交,15秒后生效');
- }
- //从其它店同步客户 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('本店无需同步');
- }
- $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('不是您的门店');
- }
- $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()
- {
- $staff = $this->shopAdmin;
- if (isset($staff->identity) && $staff->identity == 2) {
- util::success(['list' => []]);
- }
- $get = Yii::$app->request->get();
- $type = isset($get['type']) ? $get['type'] : 0;
- $name = isset($get['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';
- if ($type == 1) {
- //消费排行
- $sort = 'buyAmount DESC';
- } else if ($type == 2) {
- //欠款客户
- $where['isDebt'] = 1;
- $sort = '(debtAmount-balance) DESC';
- } else if ($type == 3) {
- $where['level'] = 0;
- } else if ($type == 4) {
- //最近未下单
- $recentDay = isset($get['recentDay']) && is_numeric($get['recentDay']) ? (int)$get['recentDay'] : 7;
- $totalSecond = bcmul(86400, $recentDay);
- $currentSecond = bcsub(time(), $totalSecond);
- $currentDate = date("Y-m-d H:i:s", $currentSecond);
- $where['recentExpend<'] = $currentDate;
- $sort = 'recentExpend desc';
- }
- $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 = isset($get['showStock']) ? $get['showStock'] : 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->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('修改成功');
- }
- //允许月结开关 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);
- }
- }
|