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(); //只要手动添加的都标记为花店,任何情况都不会标记为散客,任何情况都是审核通过的状态 $customList = CustomClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($customList)) { foreach ($customList as $custom) { $custom->isHd = 1; $custom->passStatus = 1; $custom->save(); $ghsId = $custom->ghsId; GhsClass::updateById($ghsId, ['passStatus' => 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'); } } } } }