select('id, mobile') ->orderBy('id DESC') ->asArray(); foreach ($query->batch(1000) as $allUser) { if (!empty($allUser)) { foreach ($allUser as $user) { $userId = $user['id']; $mobile = $user['mobile']; $customList = CustomClass::getAllByCondition(['userId' => $userId], null, 'id,mobile,userId'); if (!empty($customList)) { foreach ($customList as $custom) { $customId = $custom['id']; $userMobile = $custom['mobile']; if (!empty($userMobile) && $userMobile != $mobile) { echo $userId . ' ' . $customId . ' ' . $mobile . "\n"; } } } } } } } public function actionStaff() { ini_set('memory_limit', '2045M'); set_time_limit(0); $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, 'id,mainId', null, true); if (!empty($shopList)) { foreach ($shopList as $shop) { $mainId = $shop->mainId; $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, 'id,adminId,mobile', null, true); if (!empty($staffList)) { foreach ($staffList as $staff) { $adminId = $staff->adminId; $mobile = $staff->mobile; AdminClass::updateById($adminId, ['mobile' => $mobile]); echo $mobile . ' ' . $staff->id . "\n"; } } } } } public function actionCustomBuyAmount() { ini_set('memory_limit', '2045M'); set_time_limit(0); $mainId = 45354; $customList = \bizGhs\custom\classes\CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', null, true); if (!empty($customList)) { foreach ($customList as $custom) { $customId = $custom->id ?? 0; $ghsId = $custom->ghsId ?? 0; $ghs = \biz\ghs\classes\GhsClass::getById($ghsId, true); if (empty($ghs)) { continue; } $orderList = \bizGhs\order\classes\OrderClass::getAllByCondition(['customId' => $customId], null, 'id, actPrice'); $buyAmount = 0; if (!empty($orderList)) { foreach ($orderList as $order) { $buyAmount = bcadd($buyAmount, $order['actPrice'], 2); } } $custom->buyAmount = $buyAmount; $custom->save(); $ghs->expendAmount = $buyAmount; $ghs->save(); } } } public function actionShop() { $sql = "select id,shopName,`merchantName` ,ptStyle,mobile from xhShop where ptstyle = 4 and mobile not like '10000%'"; $command = Yii::$app->db->createCommand($sql); $data = $command->queryAll(); if (empty($data)) { return false; } foreach ($data as $shop) { $mobile = $shop['mobile']; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $respond = MobileSnClass::add(['id' => null], true); $newMobile = $respond->id; $staffList = StaffClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($staffList)) { foreach ($staffList as $staff) { $staff->mobile = $newMobile; $staff->save(); } } $apply = ApplyClass::getByCondition(['mobile' => $mobile], true); if (!empty($apply)) { $apply->mobile = $newMobile; $apply->save(); } $shopList = ShopClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($shopList)) { foreach ($shopList as $shop) { $shop->mobile = $newMobile; $shop->telephone = $newMobile; $shop->save(); } } $ghsCustomList = \bizGhs\custom\classes\CustomClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($ghsCustomList)) { foreach ($ghsCustomList as $custom) { $custom->mobile = $newMobile; $custom->save(); } } $ghsList = GhsClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($ghsList)) { foreach ($ghsList as $ghs) { $ghs->mobile = $newMobile; $ghs->save(); } } $hdList = HdClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($hdList)) { foreach ($hdList as $hd) { $hd->mobile = $newMobile; $hd->save(); } } $customList = CustomClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($customList)) { foreach ($customList as $custom) { $custom->mobile = $newMobile; $custom->save(); } } $userList = UserClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($userList)) { foreach ($userList as $user) { $user->mobile = $newMobile; $user->save(); } } $adminList = AdminClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true); if (!empty($adminList)) { foreach ($adminList as $admin) { $admin->mobile = $newMobile; $admin->save(); } } $transaction->commit(); echo $mobile . ' ' . $newMobile . "\n"; } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); echo $msg . "\n"; } } } public function actionCustom() { ini_set('memory_limit', '2045M'); set_time_limit(0); $list = \bizGhs\custom\classes\CustomClass::getAllByCondition(['homeAmount>' => 0], null, null, null, true); foreach ($list as $custom) { $homeType = $custom->homeType ?? 0; $homeAmount = $custom->homeAmount ?? 0; $ghsId = $custom->ghsId ?? 0; $ghs = GhsClass::getById($ghsId, true); if ($homeType === 1) { $custom->homeNum = $homeAmount; $custom->homeAmount = 0; $custom->save(); if (!empty($ghs)) { $ghs->homeNum = $homeAmount; $ghs->homeAmount = 0; $ghs->save(); } echo $custom->id . "OK\n"; } } } public function actionSendStatus() { ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->select(['id', 'sendStatus']); $query->from(Purchase::tableName()); $totalCount = 0; foreach ($query->batch(3000) as $batch) { $ids = array_column($batch, 'id'); PurchaseClass::updateByIds($ids, ['sendStatus' => -4]); $totalCount += count($ids); echo "已处理 " . $totalCount . " 条记录\n"; } echo "全部完成!共处理 " . $totalCount . " 条记录\n"; util::stop(''); ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->select(['id', 'sendStatus']); $query->from(Order::tableName()); $totalCount = 0; foreach ($query->batch(3000) as $batch) { $ids = array_column($batch, 'id'); \bizGhs\order\classes\OrderClass::updateByIds($ids, ['sendStatus' => -4]); $totalCount += count($ids); echo "已处理 " . $totalCount . " 条记录\n"; } echo "全部完成!共处理 " . $totalCount . " 条记录\n"; } public function actionSend() { set_time_limit(0); $query = new \yii\db\Query(); $query->select(['id', 'sendStatus']); $query->from(Purchase::tableName()); foreach ($query->batch() as $batch) { foreach ($batch as $order) { $id = $order['id']; PurchaseClass::updateById($id, ['sendStatus' => -2]); echo $id . "\n"; } } } //零售到店自取订单全部自动完成 ssh 20251212 public function actionOrder() { ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->select(['id', 'sendStatus']); $query->from(\bizHd\order\models\Order::tableName()); $query->where(['status' => 2, 'sendType' => 1]); $totalCount = 0; foreach ($query->batch(1000) as $batch) { $ids = array_column($batch, 'id'); OrderClass::updateByIds($ids, ['status' => 4, 'sendStatus' => -4]); $totalCount += count($ids); echo "已处理 " . $totalCount . " 条记录\n"; } echo "全部完成!共处理 " . $totalCount . " 条记录\n"; util::stop(''); } //更新核销码 ssh 20240804 public function actionCheckCode() { ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->from(CgOrder::tableName()); foreach ($query->batch() as $batch) { foreach ($batch as $cg) { $orderSn = $cg['orderSn'] ?? ''; $id = $cg['id'] ?? 0; $checkCode = substr($orderSn, -4); CgOrderClass::updateById($id, ['checkCode' => $checkCode]); } } } //更新时间 public function actionExpendTime() { ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->from(Custom::tableName()); $query->where(['recentExpend' => '0000-00-00 00:00:00']); $query->orderBy('addTime ASC'); foreach ($query->batch(50) as $customList) { if (!empty($customList)) { foreach ($customList as $custom) { $customId = $custom['id'] ?? 0; $order = \bizGhs\order\classes\OrderClass::getByCondition(['customId' => $customId, 'payStatus' => 1,], true, 'payTime DESC'); $custom = \bizGhs\custom\classes\CustomClass::getById($customId, true); if (!empty($order)) { $orderSn = $order->orderSn ?? ''; $payTime = $order->payTime; if (!empty($custom)) { $custom->recentExpend = $payTime; $custom->save(); echo $orderSn . " " . $payTime . " custom {$customId} OK \n"; } $ghsId = $custom['ghsId'] ?? 0; $ghs = \bizGhs\ghs\classes\GhsClass::getById($ghsId, true); if (!empty($ghs)) { $ghs->recentExpend = $payTime; $ghs->save(); echo $orderSn . " " . $payTime . " ghsId {$ghsId} OK \n"; } } } } } } public function actionBelong() { ini_set('memory_limit', '2045M'); set_time_limit(0); $shopList = ShopClass::getAllByCondition(['id' => ['in', [23580]]], null, '*', null, true); if (!empty($shopList)) { foreach ($shopList as $shop) { $mainId = $shop->mainId ?? 0; $list = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true); if (!empty($list)) { foreach ($list as $class) { $classId = $class->id ?? 0; $productList = ProductClass::getAllByCondition(['classId' => $classId], null, '*'); if (!empty($productList)) { $ids = array_column($productList, 'id'); if (!empty($ids)) { $o = OrderItemClass::getAllByCondition(['productId' => ['in', $ids]], null, '*', null, true); if (!empty($o)) { echo "销售单\n"; foreach ($o as $oa) { $oa->classId = $classId; $oa->save(); } } $i = \bizHd\order\classes\OrderItemClass::getAllByCondition(['itemId' => ['in', $ids]], null, '*', null, true); if (!empty($i)) { echo "花店单\n"; foreach ($i as $ia) { $ia->classId = $classId; $ia->save(); } } $n = PurchaseOrderItemClass::getAllByCondition(['productId' => ['in', $ids]], null, '*', null, true); if (!empty($n)) { echo "采购单\n"; foreach ($n as $na) { $na->classId = $classId; $na->save(); } } } } } } } } } public function actionHdCustom() { ini_set('memory_limit', '2045M'); set_time_limit(0); $customList = CustomClass::getAllByCondition(['id>' => 0], null, '*', null, true); if (!empty($customList)) { foreach ($customList as $custom) { $mobile = $custom->mobile; $custom->originName = $mobile; $custom->name = $mobile; $custom->py = $mobile; $custom->save(); OrderClass::updateByCondition(['customId' => $custom->id], ['customName' => $mobile, 'customNamePy' => $mobile]); } } } //老油花材单位比修改 ssh 20240411 public function actionLy() { if (getenv('YII_ENV') == 'production') { $mainId = 20528; } else { $mainId = 644; } $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*', null, true); if (!empty($list)) { foreach ($list as $item) { $name = $item->name ?? ''; $has = false; if (strstr($name, '100支') != false) { $ptItemId = $item->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); if (!empty($ptItem)) { $item->ratio = 100; $item->smallUnit = '支'; $item->smallUnitId = 2; $item->save(); $ptItem->ratio = 100; $ptItem->smallUnit = '支'; $ptItem->smallUnitId = 2; $ptItem->save(); $has = true; } } if (strstr($name, '200支') != false) { $ptItemId = $item->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); if (!empty($ptItem)) { $item->ratio = 200; $item->smallUnit = '支'; $item->smallUnitId = 2; $item->save(); $ptItem->ratio = 200; $ptItem->smallUnit = '支'; $ptItem->smallUnitId = 2; $ptItem->save(); $has = true; } } if ($has) { echo $name . "\n"; } } } } public function actionItem() { $list = PtItemCatRelateClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true); if (!empty($list)) { foreach ($list as $item) { $ptItemId = $item->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); echo $ptItem->name . "\n"; } } } public function actionCp() { $list = PtCpItemClass::getAllByCondition(['id>' => 0], 'id asc', '*', null, true); foreach ($list as $cp) { $ptItemId = $cp->itemId ?? 0; $ptItem = PtItemClass::getById($ptItemId, true); $ptItem->hasCpId = 1; $ptItem->save(); } } }