| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace addons\CloudStock\common\models;
- use addons\CloudStock\common\logic\deduction\DeductionJob;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_cloud_stock_push_delay_log".
- *
- * @property int $id 自增id
- * @property int $mall_id 商城id
- * @property int $user_id 用户id
- * @property int $agent_user_id 用户id
- * @property int $stock_log_id stock_log_id
- * @property int $goods_id goods_id
- * @property int $order_id order_id
- * @property int $not_yet_num 商品id
- * @property string $order_type 订单类型
- * @property string|null $time_limit_fill_user_ids
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class CloudStockPushDelayLog extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_push_delay_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'agent_user_id', 'stock_log_id', 'goods_id', 'order_id', 'not_yet_num', 'status', 'created_at', 'updated_at'], 'integer'],
- [['order_type'], 'required'],
- [['time_limit_fill_user_ids'], 'string'],
- [['order_type'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '自增id',
- 'mall_id' => '商城id',
- 'user_id' => '用户id',
- 'agent_user_id' => '用户id',
- 'stock_log_id' => 'stock_log_id',
- 'goods_id' => '商品id',
- 'order_id' => 'order_id',
- 'not_yet_num' => '商品id',
- 'order_type' => '订单类型',
- 'time_limit_fill_user_ids' => 'Time Limit Fill User Ids',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($data)
- {
- try {
- $model = self::findOne(['mall_id' => $data['mall_id'], 'status' => StatusEnum::ENABLED, 'agent_user_id' => $data['agent_user_id'], 'stock_log_id' => $data['stock_log_id']]);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $data['mall_id'];
- }
- $model->loadDefaultValues();
- if (!$model->load($data, '')) throw new \Exception($model->getErrorMessage());
- if(empty($data['time_limit_fill_user_ids'])) $data['time_limit_fill_user_ids'] = [];
- $model->time_limit_fill_user_ids = json_encode($data['time_limit_fill_user_ids']);
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- var_dump( $e->getMessage());
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public function updateDelayLog($mall_id,$goods_id,$agent_user_id,$num){
- $push_delay_logs = CloudStockPushDelayLog::lists([
- 'where'=>[
- ['mall_id'=>$mall_id],
- ['goods_id'=>$goods_id],
- ['agent_user_id'=>$agent_user_id],
- ['status' => StatusEnum::ENABLED],
- ],
- 'order'=>'id asc'
- ],false);
- if(!empty($push_delay_logs)){
- $temp_num = $num;
- foreach ($push_delay_logs as $item){
- $not_yet_num = $item['not_yet_num'];
- if($temp_num<$item['not_yet_num']){
- $not_yet_num = $temp_num;
- $temp_num = 0;
- }else{
- $temp_num-= $not_yet_num;
- }
- if($not_yet_num>0){
- $data = [
- 'user_id' => $item['user_id'],
- 'agent_user_id' => $item['agent_user_id'],
- 'stock_log_id' => $item['stock_log_id'],
- 'goods_id' => $item['goods_id'],
- 'order_id' => $item['order_id'],
- 'not_yet_num' => $not_yet_num,
- 'order_type' => $item['order_type'],
- 'mall_id' => $item['mall_id'],
- 'time_limit_fill_user_ids' =>json_decode($item['time_limit_fill_user_ids'],true),
- 'is_lock'=>false,
- ];
- (new DeductionJob())->handleSync($data);
- // $item->not_yet_num-=$not_yet_num;
- // if($item->not_yet_num<=0){
- // $item->not_yet_num = 0;
- // $item->status = -1;
- // }
- // $item->save();
- }
- }
- }
- }
- }
|