| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /*
- * @Descripttion:
- * @copyright: Copyright (c) 2021 广东七件事集团
- * @Author: lun
- * @Date: 2022-01-02 16:32:57
- */
- namespace addons\Rebate\common\models;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_rebate_statistics".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $r_id 对应qimall_addons_rebate.id
- * @property int|null $join_num 参与人数
- * @property int|null $pay_num 已支付订单数量
- * @property float $pay_money 实付金额,单位:元
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class RebateStatistics extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_rebate_statistics';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'r_id', 'join_num', 'pay_num', 'status', 'created_at', 'updated_at'], 'integer'],
- [['pay_money'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'r_id' => '对应qimall_addons_rebate.id',
- 'join_num' => '参与人数',
- 'pay_num' => '已支付订单数量',
- 'pay_money' => '实付金额,单位:元',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/1/6 0006 19:36
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param array $params
- * @return bool
- */
- public static function setData($mall_id, array $params){
- try{
- // 统计人数
- $rebate_buy_arr = RebateBuy::find()->select('user_id')->where(['mall_id' => $mall_id, 'r_id' => $params['r_id'], 'status' => 1])->groupBy("user_id")->asArray()->all();
- $num = count($rebate_buy_arr) ?? 0;
- $model = self::find()->where(['mall_id' => $mall_id, 'r_id' => $params['r_id'], 'status' => 1])->one();
- if(empty($model)){
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- $model->r_id = $params['r_id'];
- }
- $model->join_num = $num;
- $model->pay_num = $model->pay_num + 1;
- !empty($params['pay_money']) && $model->pay_money = $model->pay_money + $params['pay_money'];
- if(!$model->save()) throw new Exception($model->getErrorMessage());
- return true;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|