2], null, '*', null, true); if (empty($shopList)) { return false; } foreach ($shopList as $key => $shop) { $shopId = $shop->id ?? 0; $query = new \yii\db\Query(); $query->from(Custom::tableName()); $query->where(['ownShopId' => $shopId]); $query->orderBy('addTime ASC'); foreach ($query->batch(50) as $customList) { if (!empty($customList)) { foreach ($customList as $custom) { //$customName = $custom['name'] ?? ''; $customId = $custom['id'] ?? 0; $where = ['customId' => $customId, 'debt' => 1]; $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*'); $ghsOrderDebtAmount = 0; if (!empty($orderList)) { foreach ($orderList as $order) { $actPrice = $order['remainDebtPrice'] ?? 0; $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2); } } $ghsId = $custom['ghsId'] ?? 0; $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId); $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES]; $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*'); $hdCgOrderDebtAmount = 0; if (!empty($cgList)) { foreach ($cgList as $cg) { $actPrice = $cg['remainDebtPrice'] ?? 0; $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2); } } if ($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0) { noticeUtil::push("!!!!!!!供货商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347'); echo "@@@@@@@@@@@@@供货商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n"; } $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount); $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount); if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) { noticeUtil::push("!!!!!!!供货商 {$ghsId} 客户id {$customId} 二边欠款单总金额不一致", '15280215347'); echo "---------供货商 {$ghsId} 客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n"; continue; } $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0; $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0; if ($customSaveDebtAmount != $ghsOrderDebtAmount) { echo "*********客户 {$customId} 欠款 和 订单总额 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n"; noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347'); continue; } if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) { echo "#########欠供货商 {$ghsId} 和 订单总额 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n"; noticeUtil::push("#########欠供货商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347'); continue; } } } } } } public function actionBatchCommand() { //批量创建客户 $this->createCustomer(); //从首店同步客户 $this->copyCustomers(); } //批量创建客户 private function createCustomer() { $customerCachedKey = 'batch_create_customer_list'; $customList = []; while ($count = Yii::$app->redis->executeCommand('LLEN', [$customerCachedKey])) { $customer = Yii::$app->redis->executeCommand('RPOP', [$customerCachedKey]); $customList[] = $customer; } if (empty($customList)) { return false; } foreach ($customList as $customer) { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); $customerInfo = explode('_', $customer); $shopName = $customerInfo[0]; $mobile = $customerInfo[1]; try { // 组织表单数据 $post = []; $post['introSjId'] = $customerInfo[2]; $post['introShopId'] = $customerInfo[3]; $post['introSjName'] = $customerInfo[4]; $post['introStyle'] = SjClass::STYLE_SUPPLIER; $post['name'] = $shopName; if (empty($shopName)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347'); $transaction->rollBack(); continue; } $post['mobile'] = $mobile; if (stringUtil::isMobile($mobile) == false) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347'); $transaction->rollBack(); continue; } if (stringUtil::getWordNum($shopName) > 15) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347'); $transaction->rollBack(); continue; } $has = ApplyClass::getByCondition(['mobile' => $mobile]); if (!empty($has)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了哦", '15280215347'); $transaction->rollBack(); continue; } $hasShop = ShopClass::getByCondition(['mobile' => $mobile]); if (!empty($hasShop)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347'); $transaction->rollBack(); continue; } $adminName = $post['adminName'] ?? ''; $miniOpenId = $post['miniOpenId'] ?? ''; $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = AdminClass::replaceAdmin($adminInfo, $fromApp); $adminId = $admin['id'] ?? 0; $post['adminId'] = $adminId; $post['adminName'] = $admin['name'] ?? ''; $post['long'] = isset($post['longitude']) ? $post['longitude'] : ''; $post['lat'] = isset($post['latitude']) ? $post['latitude'] : ''; $post['from'] = ApplyClass::FROM_RETAIL; $post['style'] = SjClass::STYLE_RETAIL; //增加或更新申请 $respond = ApplyService::replaceRetail($post); $id = $respond['id'] ?? 0; //后继代码,要用到此参数 Yii::$app->params['ptStyle'] = 2; ApplyService::pass($id, '批发商手动添加'); $transaction->commit(); //只要手动添加的都标记为花店,任何情况都不会标记为散客 CustomClass::updateByCondition(['mobile' => $mobile], ['isHd' => 1]); //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功"); } catch (\Exception $exception) { $transaction->rollBack(); noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347'); } } } //批发端分店从首店同步客户 private function copyCustomers() { $cachedKey = 'copy_other_shop_customers'; $shopIdList = []; while ($count = Yii::$app->redis->executeCommand('LLEN', [$cachedKey])) { $shopIdData = Yii::$app->redis->executeCommand('RPOP', [$cachedKey]); $shopIdList[] = $shopIdData; } if (empty($shopIdList)) { return; } foreach ($shopIdList as $shopIdData) { $shopIdArr = explode('_', $shopIdData); if (count($shopIdArr) != 2) { Yii::info('copy customer 数据出错:' . $shopIdData); noticeUtil::push("从分店同步客户出错了:" . $shopIdData, '15280215347'); continue; } //指定当前环境为批发商 Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs'); $toShopId = $shopIdArr[0]; $fromShopId = $shopIdArr[1]; $fromCustomList = CustomClass::getAllByCondition(['ownShopId' => $fromShopId], null, '*'); foreach ($fromCustomList as $fromCustomer) { $exist = CustomClass::exists(['ownShopId' => $toShopId, 'shopId' => $fromCustomer['shopId']]); if (!$exist) { CustomClass::build($toShopId, $fromCustomer['shopId'], $fromCustomer['name']); } } } } //从文件批量创建客户 ssh 20240426 public function actionFileCreateCustom() { // $customerCachedKey = 'file_batch_create_customer_list'; // $fileCustomList = []; // while ($count = Yii::$app->redis->executeCommand('LLEN', [$customerCachedKey])) { // $customer = Yii::$app->redis->executeCommand('RPOP', [$customerCachedKey]); // $fileCustomList[] = $customer; // } // // if (empty($fileCustomList)) { // noticeUtil::push("没有找到手机号", '15280215347'); // return false; // } $fileCustomList = ['23580,/usr/local/nginx/html/huahuibao/vendor/../../resource/images/uploads/35869/23580/202404/27/f4ed6c0aa209b4d0d56dd6543b7c4e25.txt']; foreach ($fileCustomList as $fileCustom) { $customerInfo = explode(',', $fileCustom); $masterShopId = $customerInfo[0]; $masterShop = ShopClass::getById($masterShopId, true); $masterSjId = $masterShop->sjId ?? 0; $masterSjName = $masterShop->merchantName ?? ''; $filePath = $customerInfo[1]; $content = file_get_contents($filePath); $content = trim($content); $arr = explode(' ', $content); foreach ($arr as $key => $one) { $single = explode(',', $one); $shopName = trim($single[0]); $mobile = trim($single[1]); echo bcadd($key, 1) . ' ' . $shopName . ' ' . $mobile . "\n"; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { // 组织表单数据 $post = []; $post['introSjId'] = $masterSjId; $post['introShopId'] = $masterShopId; $post['introSjName'] = $masterSjName; $post['introStyle'] = SjClass::STYLE_SUPPLIER; $post['name'] = $shopName; if (empty($shopName)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347'); $transaction->rollBack(); continue; } $post['mobile'] = $mobile; if (stringUtil::isMobile($mobile) == false) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347'); $transaction->rollBack(); continue; } if (stringUtil::getWordNum($shopName) > 15) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347'); $transaction->rollBack(); continue; } $hasShop = ShopClass::getByCondition(['mobile' => $mobile]); if (!empty($hasShop)) { //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347'); $transaction->rollBack(); continue; } $has = ApplyClass::getByCondition(['mobile' => $mobile]); if (!empty($has)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,在申请列表,手机号已经存在了哦", '15280215347'); $transaction->rollBack(); continue; } $adminName = $post['adminName'] ?? ''; $miniOpenId = $post['miniOpenId'] ?? ''; $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = AdminClass::replaceAdmin($adminInfo, $fromApp); $adminId = $admin['id'] ?? 0; $post['adminId'] = $adminId; $post['adminName'] = $admin['name'] ?? ''; $post['long'] = isset($post['longitude']) ? $post['longitude'] : ''; $post['lat'] = isset($post['latitude']) ? $post['latitude'] : ''; $post['from'] = ApplyClass::FROM_RETAIL; $post['style'] = SjClass::STYLE_RETAIL; //增加或更新申请 $respond = ApplyService::replaceRetail($post); $id = $respond['id'] ?? 0; //后继代码,要用到此参数 Yii::$app->params['ptStyle'] = 2; ApplyService::pass($id, '批发商手动添加'); $transaction->commit(); //只要手动添加的都标记为花店,任何情况都不会标记为散客 CustomClass::updateByCondition(['mobile' => $mobile], ['isHd' => 1]); //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功"); } catch (\Exception $exception) { $transaction->rollBack(); noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347'); } } } } public function actionImport() { $masterShopId = 55238; $masterShop = ShopClass::getById($masterShopId, true); $masterSjId = $masterShop->sjId ?? 0; $masterSjName = $masterShop->merchantName ?? ''; $content = '1314花艺坊 15396301318 1314花艺坊 16521681314 贻苗鲜花店 15959886775 七里香花坊 18965691877 兰桂坊鲜花行 13774855302 星晴花艺 13559050210 好运鲜花行 15260835116 好运鲜花行 13615926212 恋善好多花 13960409739 水晶花艺坊 13559596871 华联花店 18859555183 枝也花艺 18250296177 美丽人生 13805928543 慕鑫花艺店 15980044733 温馨花店 18959765442 梦辰鲜花店 13788859910 填心花店 13505980311 车之宝 13599260160 木泽家花艺 13505909331 花·印象花艺生活馆 18750411995 恒利花艺 13599754442 友情园林花艺 13906999776 新锦堂花艺 18960312580 鑫鑫花艺 13665934834 春满园 18815989293 鑫鑫花艺 13665934834 花屿花店 18859428889 心馨鲜花行 13799553891 旺旺(铝合金太空架) 136369949 丽景花店 13506061215 幸运花艺坊 18960205098 芊禧花艺店(伊匠) 15985932041 思强花艺坊 15375751971 华盛鲜花坊 13959990453 薇FLOWER花坊 13655900006 凤艺花行 13599995559 露露发喜庆布置 13328890668 大盈优尚花艺坊 15905962910 也有花艺 15060930333 Elaine花匠·花艺 15559591557 有家花店 15859763475 彩花大道花艺坊 13600768250 新概念花店 13505906311 时光花坊 15260411999 萧下馨香园花艺 13559570456 庄园花坊 13599933509 新世纪鲜花店 13559589534 心心相印 15059510032 心馨鲜花行 13799553891 缘雅花店(雅馨) 13774814696 玲珑花艺坊13159002310 阿华花艺坊13205051057 绿园婚庆策划13599106858 水晶花艺坊13559596871 有家花店 15859763475 馨源喜庆13599709998 如意花卉13850700343 珍妮花店13655965150 简爱花店 15305090323 花屿鹿17350083333 花之翼花店13400807255 雅兰花卉水族馆13004836174 金金婚庆13675911356 米多花苑13505082530 韵香花艺13859757598 雅士花店13636952280 大众花行13860751930 艾比嘉尔(伊莉娜)18558996680 雄阿鲜花店13505957242 花禧13489366158 龙翔喜庆15805955914 花之翼花店13400807255 心相印13305964403 花满园13599933509 一沐flower13799235516 玲珑花艺 13599255169 木易花坊 18859490932 新鸿发喜庆13506067363 胖吖花店18659806189 双氧花与茶13821636888 蝶恋花13799238373 安记花艺13506957325 嘉和鲜花园林绿化工程13665962427 哈尼花店13625992221 四季红婚庆15980301977 薇薇花坊13163933983 花之林园艺13599153000 优尚鲜花婚庆15905962910 阳光花艺坊13905071762 花舍花艺13559086600 大盈经典13599128005 欣欣花坊15605002189 夏之恋18815963312 诗娜花艺13850768837 艺菲(木泽)15060815333 花样年华花店 13959868951 馨逸创艺花馆13489215832 每日鲜花15060960918 Elaine·花匠花艺15559591557 新时代花店13559551844 365鲜花坊15860426052 官桥浪漫花艺坊13338587331 薰草屋花13959776078 薰草屋花市18906098777 官桥彩花大道,13860710686 花花世界13636969069 雅馨花艺坊(石井)13799861148 新恒发18350639119 夏哥花行18650002752 花漫花店15805051191 花財鲜花店(花柬)13615962952 也有花艺工作室15260382233 瑤瑶鲜花店1385066235 福建春芽园林18960360886 莲河花店(石井)18106966733 水立方花艺 18359445626 爱慕花店 15805002864 景园花卉 18965427379 官桥-薰草屋花13959776078 东石-阿清花店15260606666 大盈-阳光花坊18065505593 绿苑鲜花坊18859998028 富红13860756709 浪漫花艺坊13338587331 水头东艺花卉坊13313883344 芒果花艺13960253306 官桥莲花15905065492 日生星花艺电话13328897135 U兰花坊15860453349 乡野情花苑18959766168 香约花店15260828070 随缘花店13808550807 环岛花艺85586592 雅馨-缘雅花艺,85705558 水头-四季花屋 13489801402 官桥水族馆-小希花艺坊13505968166 听花堂18250631192 官桥闽通花店15959860280 大盈嘉禾13665962427 梧号花店18065273656 花景苑花艺馆15959507134 壹束鲜花坊-13655979291 辉煌花艺13959952646 猫哥花艺18659073678 柒月花店15659710381 花云轩13655925866 缤纷花艺坊13808558197 心情不错花店15260801864 玉兰香花店13459583228 水头花卉盆栽15860434888 喜缘庆典 18159211358 春风鲜花行13599161081 石井予你花店15060480006 石井予你花店15060488316 圆圆花艺18965486999 圆圆花艺15059856655 艾米丽鲜花坊18859720722 漫野花艺工作室18350770045 东方鲜花精品13885906021 拾壹号花店15259742699 雅红花店 13808518072 东石-四季鲜花店15880748599 良兴花卉13365972255 星星发花艺店13506956480 (小文)花给她18649972216 阳光城-小静花坊17350911359 诗情花艺13636907311 花拾间花艺生活馆15860502983 五里花满园13959909054 花甸 13626053459 圆盘13599255169 也有花艺15260382233 兰竹轩花店13960354737 塔头月好花缘13599706376 官桥-花屿花卉18046368392 阳光花坊18065505593 秋韵花店13600754486 绿创缘花店15880829613 壹加 one+ 18016756679 涵涵花艺荟 13959872768 你好花店15159872011 官桥伊美园 17760401152 水头花述15880889419 阿清花店15260606666 阳光花坊13959851312 水头鑫花坊18659590589 金金花坊13805963733 华鑫花店15259578811 阿免-蜂缘花艺坊15306956921 爱莉Alice花坊15159560685 尤加利花店15159538922 永胜花店13959891656 彩霞-官桥芊朵鲜花店15905065492 玉峰花艺15392257576 薪雅花艺15959592427 薇妮花店18050875587 予你·番禧15060480006 15060488316 石井-唯一花坊18959963600 安海-唯一花艺坊18698351683 壹贰叁花艺 15905065127 喜见花店15106061052 花言鲜花 15880815265 英林-予你花社15715981677 鲜花悟予花店15985923946 禾下·HEXIA鲜花婚策工作室15985955869 薇薇花坊鲜花绿植13163933983 花予礼鲜花店13559592011 圆圆-A·Lin花坊18965486999 圆圆-A·Lin花坊13788807699 蔓蔓花开15396306767 小李先森花坊 15880906873 花居里婚礼派对美学13960236836 新艺花艺13600700533 薇妮买花找我18050875587 张林-有家花店18350536612 喜柿花坊15060924833 惜缘花店18259563660 蔓蔓花艺18859989782 深缘广告+梅子花艺花卉15396593380 百缘鲜花阿欣15805031767 花言鲜花店15880815265 花心思花艺15880800812 囍礼花艺13559599226 超级花花(官桥店)13338589831'; $content = trim($content); $arr = explode(' ', $content); foreach ($arr as $key => $one) { $one = trim($one); $mobile = substr($one, -11); if (!stringUtil::isMobile($mobile)) { continue; } $name = str_replace($mobile, "", $one); $shopName = $name; echo bcadd($key, 1) . ' ' . $shopName . ' ' . $mobile . "\n"; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { // 组织表单数据 $post = []; $post['introSjId'] = $masterSjId; $post['introShopId'] = $masterShopId; $post['introSjName'] = $masterSjName; $post['introStyle'] = SjClass::STYLE_SUPPLIER; $post['name'] = $shopName; if (empty($shopName)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称没有填写", '15280215347'); $transaction->rollBack(); continue; } $post['mobile'] = $mobile; if (stringUtil::isMobile($mobile) == false) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号填写错误", '15280215347'); $transaction->rollBack(); continue; } if (stringUtil::getWordNum($shopName) > 15) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,名称超过了15个汉字", '15280215347'); $transaction->rollBack(); continue; } $hasShop = ShopClass::getByCondition(['mobile' => $mobile]); if (!empty($hasShop)) { //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,手机号已经存在了", '15280215347'); $transaction->rollBack(); continue; } $has = ApplyClass::getByCondition(['mobile' => $mobile]); if (!empty($has)) { noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,在申请列表,手机号已经存在了哦", '15280215347'); $transaction->rollBack(); continue; } $adminName = $post['adminName'] ?? ''; $miniOpenId = $post['miniOpenId'] ?? ''; $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'miniOpenId' => $miniOpenId]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = AdminClass::replaceAdmin($adminInfo, $fromApp); $adminId = $admin['id'] ?? 0; $post['adminId'] = $adminId; $post['adminName'] = $admin['name'] ?? ''; $post['long'] = isset($post['longitude']) ? $post['longitude'] : ''; $post['lat'] = isset($post['latitude']) ? $post['latitude'] : ''; $post['from'] = ApplyClass::FROM_RETAIL; $post['style'] = SjClass::STYLE_RETAIL; //增加或更新申请 $respond = ApplyService::replaceRetail($post); $id = $respond['id'] ?? 0; //后继代码,要用到此参数 Yii::$app->params['ptStyle'] = 2; ApplyService::pass($id, '批发商手动添加'); $transaction->commit(); //只要手动添加的都标记为花店,任何情况都不会标记为散客 CustomClass::updateByCondition(['mobile' => $mobile], ['isHd' => 1]); noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功"); } catch (\Exception $exception) { $transaction->rollBack(); noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 添加失败,原因:" . $exception->getMessage(), '15280215347'); } } } }