| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820 |
- <?php
- namespace console\controllers;
- use biz\admin\classes\AdminClass;
- use biz\admin\classes\AdminRoleClass;
- use biz\product\classes\XjClass;
- use biz\pt\classes\PtYeChangeClass;
- use biz\recharge\classes\RechargeClass;
- use biz\shop\classes\MainClass;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopYeChangeClass;
- use biz\sj\classes\CashClass;
- use biz\sj\classes\SjClass;
- use biz\stat\classes\StatCgClass;
- use biz\stat\classes\StatCgGhsClass;
- use biz\stat\classes\StatCgGhsMonthClass;
- use biz\stat\classes\StatCgMonthClass;
- use biz\stat\classes\StatOrderCountClass;
- use biz\stat\classes\StatOutClass;
- use biz\stat\classes\StatOutMonthClass;
- use biz\stat\classes\StatPdAddClass;
- use biz\stat\classes\StatPdAddMonthClass;
- use biz\stat\classes\StatPdSubClass;
- use biz\stat\classes\StatPdSubMonthClass;
- use biz\stat\classes\StatRefundClass;
- use biz\stat\classes\StatRefundMonthClass;
- use biz\stat\classes\StatSaleClass;
- use biz\stat\classes\StatSaleMonthClass;
- use biz\stat\classes\StatStockInClass;
- use biz\stat\classes\StatStockInMonthClass;
- use biz\stat\classes\StatStockOutClass;
- use biz\stat\classes\StatStockOutMonthClass;
- use biz\stat\classes\StatWastClass;
- use biz\stat\classes\StatWastMonthClass;
- use bizGhs\cg\classes\CgClass;
- use bizGhs\clear\classes\ClearClass;
- use bizGhs\clear\models\Clear;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\order\classes\CheckOrderClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\OrderItemClass;
- use bizGhs\order\classes\RefundOrderClass;
- use bizGhs\order\classes\RefundOrderItemClass;
- use bizGhs\order\classes\StockWastageOrderClass;
- use bizGhs\order\classes\StockWastageOrderItemClass;
- use bizGhs\stat\classes\StatYjClass;
- use bizGhs\stat\classes\StatYjMonthClass;
- use bizHd\cg\classes\CgRefundClass;
- use bizHd\cg\classes\CgRefundItemClass;
- use bizHd\ghs\classes\GhsClass;
- use bizHd\goods\classes\CategoryClass;
- use bizHd\goods\classes\GoodsCategoryClass;
- use bizHd\goods\classes\GoodsClass;
- use bizHd\goods\classes\GoodsSettingClass;
- use bizHd\order\classes\OrderGoodsClass;
- use bizHd\order\models\Order;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\classes\PurchaseItemClass;
- use bizHd\saas\classes\FestRiseClass;
- use bizHd\stat\classes\StatOrderClass;
- use bizHd\stat\classes\StatOrderMonthClass;
- use bizHd\stat\classes\StatUserClass;
- use bizHd\stat\classes\StatUserMonthClass;
- use bizHd\stat\classes\StatVisitClass;
- use bizHd\stat\classes\StatVisitMonthClass;
- use bizHd\user\classes\UserClass;
- use common\components\dict;
- use common\components\stringUtil;
- use Yii;
- use yii\console\Controller;
- class InitController extends Controller
- {
- //花店订单脚本
- public function actionHdOrder()
- {
- $query = new \yii\db\Query();
- $query->from(Order::tableName());
- $query->where(['mainId' => 742]);
- foreach ($query->batch() as $batchOrder) {
- foreach ($batchOrder as $order) {
- $addTime = $order['addTime'] ?? '';
- $goodsPrice = $order['goodsPrice'] ?? 0;
- $goodsPrice = floatval($goodsPrice);
- $sendCost = $order['sendCost'] ?? 0;
- $sendCost = floatval($sendCost);
- $labourCost = $order['labourCost'] ?? 0;
- $labourCost = floatval($labourCost);
- $discountAmount = $order['discountAmount'] ?? 0;
- $discountAmount = floatval($discountAmount);
- $orderPrice = $order['orderPrice'] ?? 0;
- $orderPrice = floatval($orderPrice);
- $total = bcadd($goodsPrice, $sendCost, 2);
- $total = bcadd($total, $labourCost, 2);
- $final = bcsub($total, $discountAmount, 2);
- $final = floatval($final);
- $actPrice = $order['actPrice'] ?? 0;
- $orderSn = $order['orderSn'] ?? '';
- if ($final != $orderPrice) {
- echo "订单号:{$orderSn} {$addTime} \n";
- echo "===\n";
- $itemList = \bizHd\order\classes\OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- echo $item['name'] . " " . $item['num'] . "X" . $item['unitPrice'] . " " . $item['price'] . "\n";
- }
- }
- $goodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($goodsList)) {
- foreach ($goodsList as $goods) {
- echo $goods['name'] . " " . $goods['num'] . "X" . $goods['unitPrice'] . " " . $goods['price'] . "\n";
- }
- }
- echo "===\n";
- echo "商品总和:{$goodsPrice} \n 运费:{$sendCost} \n人工包装费:{$labourCost} \n合计:{$total} \n优惠:{$discountAmount}\n 订单金额:{$orderPrice} \n 实付金额:{$actPrice}\n\n\n\n\n";
- }
- }
- }
- }
- //花材菜单 ./yii init/menu
- public function actionMenu()
- {
- $sql = "ALTER TABLE xhGhsItemClass ADD shopId INT NOT NULL DEFAULT 0 COMMENT '门店id' AFTER sjId;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE xhAdminRole ADD shopId INT NOT NULL DEFAULT 0 COMMENT '门店id' AFTER `sjId`;";
- Yii::$app->db->createCommand($sql)->execute();
- $list = SjClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($list)) {
- foreach ($list as $sj) {
- $sjId = $sj->id ?? 0;
- if (empty($sjId)) {
- continue;
- }
- $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
- if (empty($shopList)) {
- continue;
- }
- //补花材
- $classList = ItemClassClass::getAllByCondition(['sjId' => $sjId], null, '*');
- if (!empty($classList)) {
- foreach ($shopList as $shop) {
- $shopId = $shop->id ?? 0;
- foreach ($classList as $class) {
- $classId = $class['id'] ?? 0;
- $name = $class['name'] ?? '';
- $inTurn = $class['inTurn'] ?? '';
- $isDefault = $class['isDefault'] ?? 0;
- $data = [
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'name' => $name,
- 'inTurn' => $inTurn,
- 'isDefault' => $isDefault,
- ];
- $r = ItemClassClass::add($data, true);
- $newId = $r->id ?? 0;
- ItemClass::updateByCondition(['shopId' => $shopId, 'classId' => $classId], ['classId' => $newId]);
- }
- }
- }
- //补角色
- $roleList = AdminRoleClass::getAllByCondition(['sjId' => $sjId], null, '*');
- if (!empty($roleList)) {
- foreach ($shopList as $shop) {
- $shopId = $shop->id ?? 0;
- foreach ($roleList as $role) {
- $roleName = $role['roleName'] ?? '';
- $roleId = $role['id'] ?? 0;
- $roleData = [
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'roleName' => $roleName,
- ];
- $new = AdminRoleClass::add($roleData, true);
- $newId = $new->id ?? 0;
- ShopAdminClass::updateByCondition(['shopId' => $shopId, 'roleId' => $roleId], ['roleId' => $newId]);
- }
- }
- }
- }
- }
- }
- //初始化 ./yii init/main
- public function actionMain()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- //基地批发商
- $jdShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'kmGhs')], 'default DESC', '*', null, true);
- if (!empty($jdShopList)) {
- foreach ($jdShopList as $jdShop) {
- $main = MainClass::add(['id' => null], true);
- $mainId = $main->id ?? 0;
- if (empty($mainId)) {
- echo "mainId没有生成 \n";
- exit();
- }
- $jdShop->mainId = $mainId;
- $jdShop->save();
- }
- }
- //批发商
- $pfShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'ghs')], 'default DESC', '*', null, true);
- if (!empty($pfShopList)) {
- foreach ($pfShopList as $pfShop) {
- $pfShopId = $pfShop->id ?? 0;
- $main = MainClass::add(['id' => null], true);
- $mainId = $main->id ?? 0;
- if (empty($mainId)) {
- echo "mainId没有生成 \n";
- exit();
- }
- $pfShop->mainId = $mainId;
- $pfShop->save();
- //将shop资产信息迁移到main
- self::migration($main, $pfShop);
- //员工数据迁移到currentGhsShopId,删除零售和基地供应商的管理员信息
- $staffList = ShopAdminClass::getAllByCondition(['shopId' => $pfShopId], null, '*');
- if (!empty($staffList)) {
- foreach ($staffList as $staff) {
- $pfAdminId = $staff['adminId'] ?? 0;
- $pfAdmin = AdminClass::getById($pfAdminId, true);
- if (!empty($pfAdmin)) {
- if (empty($pfAdmin->currentGhsShopId)) {
- $pfAdmin->currentGhsShopId = $pfShopId;
- $pfAdmin->ghsMiniOpenId = $pfAdmin->miniOpenId ?? '';
- $pfAdmin->miniOpenId = '';
- $pfAdmin->currentShopId = 0;
- $pfAdmin->save();
- }
- } else {
- echo "没有找到shopId:{$pfShopId}批发店的员工\n";
- }
- $staffMobile = $staff['mobile'] ?? '';
- //删除和批发店用一样手机号的 零售和基地供应商 员工
- if (!empty($staffMobile)) {
- $h = AdminClass::getAllByCondition(['mobile' => $staffMobile, 'style' => dict::getDict('ptStyle', 'hd')], null, '*', null, true);
- if (!empty($h)) {
- foreach ($h as $he) {
- $currentAdminId = $he->id ?? 0;
- ShopAdminClass::deleteByCondition(['adminId' => $currentAdminId]);
- $he->delete();
- }
- }
- $j = AdminClass::getAllByCondition(['mobile' => $staffMobile, 'style' => dict::getDict('ptStyle', 'kmGhs')], null, '*', null, true);
- if (!empty($j)) {
- foreach ($j as $je) {
- $currentAdminId = $je->id ?? 0;
- ShopAdminClass::deleteByCondition(['adminId' => $currentAdminId]);
- $je->delete();
- }
- }
- }
- }
- }
- //花材和分类,零售和批发都有,单独拎出来
- ItemClass::updateByCondition(['shopId' => $pfShopId], ['mainId' => $mainId]);
- ItemClassClass::updateByCondition(['shopId' => $pfShopId], ['mainId' => $mainId]);
- self::setCommon($pfShopId, $mainId);
- self::setGhs($pfShopId, $mainId);
- }
- }
- //零售
- $lsShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'hd')], 'default DESC', '*', null, true);
- if (!empty($lsShopList)) {
- foreach ($lsShopList as $lsShop) {
- $main = MainClass::add(['id' => null], true);
- $mainId = $main->id ?? 0;
- if (empty($mainId)) {
- echo "mainId没有生成 \n";
- exit();
- }
- $lsShop->mainId = $mainId;
- $lsShop->save();
- $lsShopId = $lsShop->id ?? 0;
- $lsSjId = $lsShop->sjId ?? 0;
- //将shop资产信息迁移到main
- self::migration($main, $lsShop);
- $staffList = ShopAdminClass::getAllByCondition(['shopId' => $lsShopId], null, '*');
- if (!empty($staffList)) {
- foreach ($staffList as $staff) {
- $adminId = $staff['adminId'] ?? 0;
- $admin = AdminClass::getById($adminId, true);
- if (!empty($admin)) {
- if (empty($admin->currentShopId)) {
- $admin->currentShopId = $lsShopId;
- $admin->save();
- }
- }
- }
- }
- //花材和分类,零售和批发都有,单独拎出来
- ItemClass::updateByCondition(['shopId' => $lsShopId], ['mainId' => $mainId]);
- ItemClassClass::updateByCondition(['shopId' => $lsShopId], ['mainId' => $mainId]);
- self::setCommon($lsShopId, $mainId);
- self::setHd($lsSjId, $lsShopId, $mainId);
- }
- }
- //清除零售商城相关的数据
- $sql = "TRUNCATE xhUser;TRUNCATE xhCustom;truncate xhUserAsset;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "UPDATE xhOrder SET customId=0,customName='',alipayId=0;";
- Yii::$app->db->createCommand($sql)->execute();
- //补已经存在花店的默认客户
- $lsShopList = ShopClass::getAllByCondition(['ptStyle' => dict::getDict('ptStyle', 'hd')], null, '*', null, true);
- if (!empty($lsShopList)) {
- foreach ($lsShopList as $lsShop) {
- $mobile = $lsShop->mobile ?? 0;
- if (empty($mobile) || stringUtil::isMobile($mobile) == false) {
- continue;
- }
- $user = UserClass::replaceUser(['mobile' => $mobile]);
- $custom = \bizHd\custom\classes\CustomClass::replaceCustom($lsShop, $user);
- $customId = $custom->id ?? 0;
- $lsShop->defaultCustomId = $customId;
- $lsShop->save();
- }
- }
- //欠款字段迁移
- $sql = 'UPDATE xhGhsOrder SET debtPrice=actPrice,remainDebtPrice=actPrice WHERE debt=1';
- Yii::$app->db->createCommand($sql)->execute();
- $sql = 'UPDATE xhCg SET debtPrice=actPrice,remainDebtPrice=actPrice WHERE debt=1;';
- Yii::$app->db->createCommand($sql)->execute();
- $map = [];
- $allShop = ShopClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($allShop)) {
- foreach ($allShop as $single) {
- $mainId = $single->mainId ?? 0;
- $shopId = $single->id ?? 0;
- $map[$shopId] = $mainId;
- }
- }
- //供应商的销售单 和 零售的退款单,老字段数据要迁到新字段数据上
- $ghsSaleRefund = [];
- $hdCgRefund = [];
- $refundList = RefundOrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($refundList)) {
- foreach ($refundList as $key => $refund) {
- $orderSn = $refund->orderSn ?? '';
- $relateOrderSn = $refund->relateOrderSn ?? '';
- $shopId = $refund->shopId ?? 0;
- $mainId = $map[$shopId] ?? 0;
- $refund->mainId = $mainId;
- $refund->save();
- if (empty($orderSn)) {
- continue;
- }
- $refundItemList = RefundOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($refundItemList)) {
- foreach ($refundItemList as $refundItem) {
- $refundItem->xhNum = floatval($refundItem->itemNum);
- $refundItem->xhUnitName = '扎';
- $refundItem->xhUnitType = 0;
- $refundItem->xhUnitPrice = $refundItem->itemPrice;
- $refundItem->xhPrice = bcmul($refundItem->itemPrice, $refundItem->itemNum, 2);
- $refundItem->mainId = $mainId;
- $refundItem->save();
- $productId = $refundItem->productId ?? 0;
- $ghsSaleRefund[$relateOrderSn][$productId] = floatval($refundItem->itemNum);
- }
- }
- }
- }
- $cgRefundList = CgRefundClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($cgRefundList)) {
- foreach ($cgRefundList as $cgRefund) {
- $orderSn = $cgRefund->orderSn ?? '';
- $cgId = $cgRefund->cgId ?? 0;
- $shopId = $cgRefund->shopId ?? 0;
- $mainId = $map[$shopId] ?? 0;
- $cgRefund->mainId = $mainId;
- $cgRefund->save();
- if (empty($orderSn)) {
- continue;
- }
- $cgRefundItemList = CgRefundItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($cgRefundItemList)) {
- foreach ($cgRefundItemList as $cgItem) {
- $cgItem->xhNum = floatval($cgItem->itemNum);
- $cgItem->xhUnitName = '扎';
- $cgItem->xhUnitType = 0;
- $cgItem->xhUnitPrice = $cgItem->itemPrice;
- $cgItem->xhPrice = bcmul($cgItem->itemPrice, $cgItem->itemNum, 2);
- $cgItem->mainId = $mainId;
- $cgItem->save();
- $productId = $cgItem->productId ?? 0;
- $hdCgRefund[$cgId][$productId] = floatval($cgItem->itemNum);
- }
- }
- }
- }
- //供应商的销售单 和 零售的采购单,老字段数据要迁到新字段数据上
- $orderList = OrderClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($orderList)) {
- foreach ($orderList as $order) {
- $orderSn = $order->orderSn ?? '';
- if (empty($orderSn)) {
- continue;
- }
- $order->orderPrice = bcadd($order->prePrice, $order->discountAmount, 2);
- $order->save();
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $orderItem) {
- $productId = $orderItem->productId ?? 0;
- $refundNum = $ghsSaleRefund[$orderSn][$productId] ?? 0;
- $bigNum = $orderItem->bigNum ?? 0;
- $smallNum = $orderItem->smallNum ?? 0;
- $unitPrice = $orderItem->unitPrice ?? 0;
- $smallUnitPrice = $orderItem->smallUnitPrice ?? 0;
- if ($bigNum > 0) {
- $xhUnitType = 0;
- $xhUnitName = '扎';
- $xhNum = $bigNum;
- $xhUnitPrice = $unitPrice;
- } else {
- $xhUnitType = 1;
- $xhUnitName = '支';
- $xhNum = $smallNum;
- $xhUnitPrice = $smallUnitPrice;
- }
- $orderItem->xhNum = $xhNum;
- $orderItem->xhUnitName = $xhUnitName;
- $orderItem->xhUnitType = $xhUnitType;
- $orderItem->xhUnitPrice = $xhUnitPrice;
- $orderItem->xhPrice = bcmul($xhNum, $xhUnitPrice, 2);
- $orderItem->xhPreNum = 0;
- $orderItem->xhPreUnitName = 0;
- $orderItem->xhPreUnitType = 0;
- $orderItem->xhPreUnitPrice = 0;
- $orderItem->xhPrePrice = 0;
- //refundNum 已退货数量
- $orderItem->refundNum = $refundNum;
- $orderItem->save();
- }
- }
- }
- }
- $cgList = PurchaseClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($cgList)) {
- foreach ($cgList as $cg) {
- $orderSn = $cg->orderSn ?? '';
- $cgId = $cg->id ?? 0;
- if (empty($orderSn)) {
- continue;
- }
- $cg->orderPrice = bcsub($cg->prePrice, $cg->discountAmount, 2);
- $cg->save();
- $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($cgItemList)) {
- foreach ($cgItemList as $cgItem) {
- $productId = $cgItem->productId ?? 0;
- $refundNum = $hdCgRefund[$cgId][$productId] ?? 0;
- if (floor($cgItem->itemNum) == $cgItem->itemNum) {
- $xhNum = $cgItem->itemNum;
- $xhUnitType = 0;
- $xhUnitName = '扎';
- $xhUnitPrice = $cgItem->price;
- $xhPrice = $cgItem->totalPrice;
- } else {
- $xhUnitType = 1;
- $xhUnitName = '支';
- $xhNum = bcmul($cgItem->ratio, $cgItem->itemNum);
- $xhUnitPrice = $cgItem->smallPrice;
- $xhPrice = $cgItem->totalPrice;
- }
- $cgItem->xhNum = $xhNum;
- $cgItem->xhUnitName = $xhUnitName;
- $cgItem->xhUnitType = $xhUnitType;
- $cgItem->xhUnitPrice = $xhUnitPrice;
- $cgItem->xhPrice = $xhPrice;
- $cgItem->refundNum = $refundNum;
- $cgItem->save();
- }
- }
- }
- }
- //将平台花材的散客加价设置为8,花店加价设置为6,同行加价设置为4
- $sql = 'UPDATE `xhPtItem` SET `skAddPrice`=8,`addPrice`=6,`hjAddPrice`=4;';
- Yii::$app->db->createCommand($sql)->execute();
- self::migrationDel();
- //客户和供应商的中央化
- self::ghsCustomMain($map);
- }
- //客户和供应商的中央化 ssh 20220506
- public static function ghsCustomMain($map)
- {
- $customList = CustomClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($customList)) {
- foreach ($customList as $custom) {
- $shopId = $custom->shopId ?? 0;
- $mainId = $map[$shopId] ?? 0;
- $custom->mainId = $mainId;
- $ownShopId = $custom->ownShopId ?? 0;
- $ownMainId = $map[$ownShopId] ?? 0;
- $custom->ownMainId = $ownMainId;
- $custom->save();
- }
- }
- $ghsList = GhsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- foreach ($ghsList as $ghs) {
- $shopId = $ghs->shopId ?? 0;
- $mainId = $map[$shopId] ?? 0;
- $ghs->mainId = $mainId;
- $ownShopId = $ghs->ownShopId ?? 0;
- $ownMainId = $map[$ownShopId] ?? 0;
- $ghs->ownMainId = $ownMainId;
- $ghs->save();
- }
- }
- public static function setCommon($shopId, $mainId)
- {
- ShopAdminClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- CashClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- AdminRoleClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- CheckOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatPdAddClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatPdAddMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatPdSubClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatPdSubMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatWastClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatWastMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- }
- public static function setGhs($shopId, $mainId)
- {
- StatSaleClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatSaleMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatUserClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatUserMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatVisitClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatVisitMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatOutClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatOutMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- PtYeChangeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- ShopYeChangeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- RechargeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatYjClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatYjMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatOrderMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatOrderCountClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- RefundOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- //采购统计
- StatCgClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatCgMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatCgGhsClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatCgGhsMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- CustomClass::updateByCondition(['ownShopId' => $shopId], ['ownMainId' => $mainId]);
- StatStockOutClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatStockOutMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatStockInClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatStockInMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatRefundClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- StatRefundMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- CgClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- XjClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- //报损中央化
- StockWastageOrderClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- $wastageList = StockWastageOrderClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($wastageList)) {
- foreach ($wastageList as $wastage) {
- $wastageOrderSn = $wastage->orderSn ?? 0;
- StockWastageOrderItemClass::updateByCondition(['orderSn' => $wastageOrderSn], ['mainId' => $mainId]);
- }
- }
- }
- public static function setHd($sjId, $shopId, $mainId)
- {
- GoodsClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
- GoodsCategoryClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
- CategoryClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
- GoodsSettingClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
- FestRiseClass::updateByCondition(['sjId' => $sjId], ['mainId' => $mainId]);
- GhsClass::updateByCondition(['ownShopId' => $shopId], ['ownMainId' => $mainId]);
- PurchaseClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
- }
- public static function migration($main, $shop)
- {
- //shop数据迁移到main,保存之后请在migrationDel()增加对应字段!!!!!!
- $main->balance = $shop->balance ?? 0;
- $main->freezeBalance = $shop->freezeBalance ?? 0;
- $main->txBalance = $shop->txBalance ?? 0;
- $main->fixBalance = $shop->fixBalance ?? 0;
- $main->totalRecharge = $shop->totalRecharge ?? 0;
- $main->totalIncome = $shop->totalIncome ?? 0;
- $main->totalExpend = $shop->totalExpend ?? 0;
- $main->totalPurchase = $shop->totalPurchase ?? 0;
- $main->totalItem = $shop->totalItem ?? 0;
- $main->totalSale = $shop->totalSale ?? 0;
- $main->totalStockIn = $shop->totalStockIn ?? 0;
- $main->totalStockOut = $shop->totalStockOut ?? 0;
- $main->totalRefund = $shop->totalRefund ?? 0;
- $main->totalWast = $shop->totalWast ?? 0;
- $main->totalPdSub = $shop->totalPdSub ?? 0;
- $main->totalPdAdd = $shop->totalPdAdd ?? 0;
- $main->totalPurchaseOrder = $shop->totalPurchaseOrder ?? 0;
- $main->totalUser = $shop->totalUser ?? 0;
- $main->totalVisit = $shop->totalVisit ?? 0;
- $main->totalView = $shop->totalView ?? 0;
- $main->cashName = $shop->cashName ?? '';
- $main->cashAccount = $shop->cashAccount ?? '';
- $main->cashBank = $shop->cashBank ?? '';
- $main->cgUnPay = $shop->cgUnPay ?? 0;
- $main->cgUnSend = $shop->cgUnSend ?? 0;
- $main->cgSending = $shop->cgSending ?? 0;
- $main->cgFinish = $shop->cgFinish ?? 0;
- $main->cgCancel = $shop->cgCancel ?? 0;
- $main->mayGatheringNum = $shop->mayGatheringNum ?? 0;
- $main->mayGathering = $shop->mayGathering ?? 0;
- $main->mayPay = $shop->mayPay ?? 0;
- $main->mayPayNum = $shop->mayPayNum ?? 0;
- $main->totalOrder = $shop->totalOrder ?? 0;
- $main->totalOrderNum = $shop->totalOrderNum ?? 0;
- $main->finishOrder = $shop->finishOrder ?? 0;
- $main->unPayOrder = $shop->unPayOrder ?? 0;
- $main->unSendOrder = $shop->unSendOrder ?? 0;
- $main->sendingOrder = $shop->sendingOrder ?? 0;
- $main->cancelOrder = $shop->cancelOrder ?? 0;
- $main->save();
- }
- //迁移完成之后删除xhShop对应字段
- public static function migrationDel()
- {
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `balance`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `freezeBalance`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `txBalance`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `fixBalance`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalRecharge`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalIncome`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalExpend`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPurchase`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalItem`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalSale`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalStockIn`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalStockOut`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalRefund`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalWast`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPdSub`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPdAdd`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalPurchaseOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalUser`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalVisit`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalView`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cashName`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cashAccount`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cashBank`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgUnPay`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgUnSend`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgSending`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgFinish`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cgCancel`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayGathering`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayGatheringNum`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayPay`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `mayPayNum`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `totalOrderNum`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `finishOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `unPayOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `unSendOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `sendingOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- $sql = "ALTER TABLE `xhShop` DROP COLUMN `cancelOrder`;";
- Yii::$app->db->createCommand($sql)->execute();
- }
- //结账单补数据
- public function actionClear()
- {
- $query = new \yii\db\Query();
- $query->from(Clear::tableName());
- $query->where(['>', 'id', 0]);
- $query->orderBy('addTime ASC');
- foreach ($query->batch() as $clearBatch) {
- $batchGhsId = array_column($clearBatch, 'ghsId');
- $batchCustomId = array_column($clearBatch, 'customId');
- $batchGhsId = array_unique(array_filter($batchGhsId));
- $batchCustomId = array_unique(array_filter($batchCustomId));
- $customInfo = CustomClass::getByIds($batchCustomId, null, 'id');
- $ghsInfo = GhsClass::getByIds($batchGhsId, null, 'id');
- foreach ($clearBatch as $clear) {
- $id = $clear['id'];
- $clearStyle = $clear['clearStyle'] ?? 1;
- if ($clearStyle != dict::getDict('clearStyle', 'gys2KmGys')) {
- $customId = $clear['customId'] ?? 0;
- $ghsId = $clear['ghsId'] ?? 0;
- $customShopId = $customInfo[$customId]['shopId'] ?? 0;
- $ghsShopId = $ghsInfo[$ghsId]['shopId'] ?? 0;
- $params = ['customShopId' => $customShopId, 'ghsShopId' => $ghsShopId];
- ClearClass::updateById($id, $params);
- } else {
- $currentGhsId = $clear['ghsId'] ?? 0;
- if (empty($currentGhsId)) {
- echo "出现空的ghsId clearId:{$id} \n";
- continue;
- }
- $currentGhs = GhsClass::getById($currentGhsId, true);
- $currentCustomId = $currentGhs->customId ?? 0;
- $currentCustom = CustomClass::getById($currentCustomId, true);
- $customShopId = $currentCustom->shopId ?? 0;
- $ghsShopId = $currentGhs->shopId ?? 0;
- $params = ['customShopId' => $customShopId, 'customId' => $currentCustomId, 'ghsShopId' => $ghsShopId];
- ClearClass::updateById($id, $params);
- }
- }
- }
- }
- }
|