| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace addons\Area\common\models;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\helpers\FormatHelper;
- use common\models\common\CapitalLog;
- use common\models\order\Order;
- use Exception;
- use RuntimeException;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_area_order_settlement_log".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $status
- * @property int $order_id
- * @property int $created_at
- * @property int $updated_at
- */
- class AreaOrderSettlementLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_area_order_settlement_log';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'status', 'order_id', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'status' => 'Status',
- 'order_id' => 'Order ID',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @param array $params
- *
- * @return bool|self
- */
- public static function setData(array $params)
- {
- try {
- $model = self::findOne(['order_id' => $params['order_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (!$model) {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) {
- throw new RuntimeException($model->getErrorMessage());
- }
- if (!$model->save()) {
- throw new RuntimeException($model->getErrorMessage());
- }
- return $model;
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @param array $insertData
- *
- * @return bool
- */
- public static function batchInsertData(array $insertData): bool
- {
- if (empty($insertData)) {
- return true;
- }
- $time = time();
- $batchInsertData = [];
- foreach ($insertData as $insertDataItem) {
- $batchInsertData[] = array_merge($insertDataItem, [
- 'created_at' => $time,
- 'updated_at' => $time,
- ]);
- }
- try {
- Yii::$app
- ->db
- ->createCommand()
- ->batchInsert(self::tableName(), array_keys($batchInsertData[0]), $batchInsertData)
- ->execute();
- } catch (Exception $e) {
- Yii::$app->custom->logs(FormatHelper::exception($e, sprintf('【区域管理】同步已结算订单到%s表失败', self::tableName())));
- return false;
- }
- return true;
- }
- /**
- * @return void
- */
- public static function fixData()
- {
- $commission_wallet_type = 'commission';
- CapitalLog::$capitalType = "{$commission_wallet_type}_frozen";
- $find = CapitalLog::find();
- $params = [
- 'where' => [
- ['from_type' => AddonsEnum::ADDONS_NAME_AREA]
- ],
- 'select' => 'order_no'
- ];
- CapitalLog::paramPack($params, $find);
- foreach ($find->asArray()->batch(2000) as $batchItem) {
- self::batchInsertData(
- Order::find()
- ->where([
- 'order_no' => array_column($batchItem, 'order_no')
- ])
- ->select('id order_id, mall_id')
- ->asArray()
- ->all()
- );
- }
- }
- }
|