| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace console\controllers;
- use bizHd\balance\classes\BalanceChangeClass;
- use bizHd\custom\classes\CustomClass;
- use bizHd\custom\classes\HdClass;
- use bizHd\custom\models\Custom;
- use bizHd\shop\models\Shop;
- use common\components\dict;
- use common\components\util;
- use yii\console\Controller;
- use Yii;
- class LsCustomController extends Controller
- {
- public function actionIndex()
- {
- //先确认所有客户的欠款总数跟账单总和能不能对应上 ssh 20250620
- //批发不需要这一步
- //零售要去数据库确认这一步
- }
- public function actionMigrate()
- {
- $query = new \yii\db\Query();
- $query->from(Shop::tableName());
- $query->where(['ptStyle' => 1]);
- $query->orderBy('addTime DESC');
- foreach ($query->batch(20) as $shopList) {
- foreach ($shopList as $shop) {
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopId = $shop['id'] ?? 0;
- $query = new \yii\db\Query();
- $query->from(Custom::tableName());
- $query->where(['shopId' => $shopId]);
- $query->orderBy('addTime ASC');
- foreach ($query->batch(500) as $customList) {
- foreach ($customList as $custom) {
- $customId = $custom['id'] ?? 0;
- $debtAmount = $custom['debtAmount'] ?? 0;
- $hdId = $custom['hdId'] ?? 0;
- $customName = $custom['name'] ?? '';
- if (empty($hdId) || empty($customId)) {
- echo $customName . " customId:" . $customId . " hdId:" . $hdId . " 的ID是空的 \n";
- util::stop();
- }
- if ($debtAmount > 0) {
- echo "shopId:" . $shopId . " | " . $customName . " customId:" . $customId . " hdId:" . $hdId . " 有欠款 ==== \n\n";
- $custom = CustomClass::getById($customId, true);
- $hd = HdClass::getById($hdId, true);
- if (empty($custom) || empty($hd)) {
- echo $customName . " customId:" . $customId . " hdId:" . $hdId . " 的对象是空的哦!! \n";
- util::stop();
- }
- $balance = $custom->balance ?? 0;
- $hdBalance = $hd->balance ?? 0;
- if (floatval($balance) != $hdBalance) {
- echo $customName . " customId:" . $customId . " hdId:" . $hdId . " 二边余额不一致 \n";
- util::stop();
- }
- $newBalance = bcsub($balance, $debtAmount, 2);
- $custom->balance = $newBalance;
- $custom->debtAmount = 0;
- $custom->isDebt = 0;
- $custom->debtNum = 0;
- $custom->save();
- $hd->balance = $newBalance;
- $hd->debtAmount = 0;
- $hd->debt = 1;
- $hd->debtNum = 0;
- $hd->save();
- $hdName = $hd->name ?? '';
- $mainId = $shop['mainId'] ?? 0;
- $event = '系统操作,合并欠款到余额';
- $capitalType = dict::getDict('capitalType', 'system', 'id');
- $change = [
- 'customId' => $customId,
- 'customName' => $customName,
- 'hdId' => $hdId,
- 'hdName' => $hdName,
- 'relateId' => 0,
- 'onlinePay' => 1,
- 'capitalType' => $capitalType,
- 'amount' => $debtAmount,
- 'balance' => $newBalance,
- 'io' => 0,
- 'side' => 0,
- 'payWay' => 0,
- 'event' => $event,
- 'staffId' => 0,
- 'staffName' => '',
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'remark' => '',
- ];
- BalanceChangeClass::add($change, true);
- } else {
- //echo "shopId:".$shopId." | ".$customName . " customId:" . $customId . " hdId:" . $hdId . " 没有欠款 ok ok \n";
- }
- }
- }
- $transaction->commit();
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- echo "报错了:" . $msg . "\n";
- }
- }
- }
- }
- }
|