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; } }