| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace addons\Recharge\common\models;
- use addons\Recharge\common\enums\RechargeEnum;
- use common\enums\StatusEnum;
- use common\models\common\RechargeOrders;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_recharge_active}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $name 活动名称
- * @property int $start_at 开始时间
- * @property int $end_at 结束时间
- * @property int|null $already_give 已赠送人数
- * @property string $give_desc 赠送说明
- * @property int $give_cond 赠送条件 0/单次充值 1/累计充值(活动时间内)
- * @property string $give_info 赠送具体信息
- * @property int $active_status 0/未开始 1/进行中 2/已过期 3/已停用
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class AddonsRechargeActive extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_recharge_active}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'start_at', 'end_at', 'already_give', 'give_cond', 'active_status', 'status', 'created_at', 'updated_at'], 'integer'],
- [['give_cond', 'give_info'], 'required'],
- [['give_info'], 'string'],
- [['name'], 'string', 'max' => 100],
- [['give_desc'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => '活动名称',
- 'start_at' => '开始时间',
- 'end_at' => '结束时间',
- 'already_give' => '已赠送人数',
- 'give_desc' => '赠送说明',
- 'give_cond' => '赠送条件 0/单次充值 1/累计充值(活动时间内)',
- 'give_info' => '赠送具体信息',
- 'active_status' => '0/未开始 1/进行中 2/已过期 3/已停用',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($params, $mall_id): bool
- {
- try {
- if (isset($params['id']) && $params['id'] > 0) {
- $model = self::findOne(['id' => $params['id']]);
- } else {
- $model = new self();
- $model->mall_id = $mall_id;
- $model->loadDefaultValues();
- }
- $model->load($params, '');
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return true;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public function getNowActive($mall_id)
- {
- $now = time();
- $where = [
- ['=', 'mall_id', $mall_id],
- ['<', 'start_at', $now],
- ['>', 'end_at', $now],
- ['=', 'active_status', RechargeEnum::ACTIVE_STATUS1],
- ['=', 'status', StatusEnum::ENABLED],
- ];
- $active_list = self::lists(['where' => $where], true);
- $data = [];
- if ($active_list) {
- foreach ($active_list as $key => $row) {
- $start_at[$key] = $row['start_at'];
- $create_at[$key] = $row['created_at'];
- }
- //start_at 优先 若相同 则根据created_at倒序
- array_multisort($start_at, SORT_DESC, $create_at, SORT_DESC, $active_list);
- $data = $active_list[0];
- $data['give_info'] = Json::decode($data['give_info']);
- }
- return $data;
- }
- public function getNowActiveList($mall_id)
- {
- $now = time();
- $where = [
- ['=', 'mall_id', $mall_id],
- ['<', 'start_at', $now],
- ['>', 'end_at', $now],
- ['=', 'active_status', RechargeEnum::ACTIVE_STATUS1],
- ['=', 'status', StatusEnum::ENABLED],
- ];
- $active_list = self::lists(['where' => $where,'order' => 'id desc'], true);
- if ($active_list) {
- foreach ($active_list as $key => $row) {
- $row['give_info'] = Json::decode($row['give_info']);
- $active_list[$key] = $row;
- }
- }
- return $active_list;
- }
- public static function check($params): bool
- {
- $order_no_arr = $params['order_no_arr'];
- $payment_order_list = $params['payment_order_list'];
- $counts = RechargeOrders::find()->where(['order_no'=>$order_no_arr,'is_pay'=>0])->count();
- if ($counts != count($payment_order_list)) {
- self::$static_error = '充值订单不一致';
- return false;
- }
- return true;
- }
- }
|