| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace addons\Agent\common\models;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\helpers\FormatHelper;
- use common\logic\common\ConditionUpgrade;
- use common\models\base\BaseActiveRecord;
- use common\models\user\User;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_agent_apply".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property string $mobile
- * @property string $name
- * @property string $remark
- * @property string $check_remark
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $check_status 0待审核1审核通过2不通过
- * @property int $created_at
- * @property int $updated_at
- */
- class AgentApply extends BaseActiveRecord
- {
- const CHECK_STATUS_WAIT = 0;
- const CHECK_STATUS_SUCCESS = 1;
- const CHECK_STATUS_FAIL = 2;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_agent_apply}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'mobile', 'name'], 'required'],
- [['mall_id', 'user_id', 'status', 'check_status', 'created_at', 'updated_at'], 'integer'],
- [['mobile', 'name'], 'string', 'max' => 45],
- [['remark','check_remark'], 'string', 'max' => 1000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'mobile' => 'Mobile',
- 'name' => 'Name',
- 'remark' => 'remark',
- 'check_remark' => 'check_remark',
- 'status' => 'Status',
- 'check_status' => 'Check Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public static function setData(array $params)
- {
- $t = Yii::$app->db->beginTransaction();
- try {
- if(!empty($params['id'])){
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new Exception('服务不存在或已删除');
- $params['user_id'] = $model->user_id;
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- if(!empty($params['check_status'])&&$params['check_status']==1){
- //不需要审核
- $res = Agent::findOne(['mall_id'=>$params['mall_id'],'user_id'=>$params['user_id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if(!empty($res)) throw new Exception('该会员已经开启渠道分红');
- // $agent_model = new Agent();
- // $agent_model->mall_id = $params['mall_id'];
- // $agent_model->user_id = $params['user_id'];
- // $agent_model->level = 0;
- // $agent_model->upgrade_level_at = 0;
- // $agent_model->upgrade_status = 0;
- // $res = $agent_model->save();
- // if(!$res) throw new \Exception($agent_model->getErrorMessage());
- }
- $t->commit();
- return $model;
- } catch (\Exception $e) {
- $t->rollBack();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 申请通过后,升级处理
- * @param $params
- * @return array|bool
- */
- public function upgradeLevel($params)
- {
- try{
- $mall_id = $params['mall_id'];
- $user_id = $params['user_id'];
- $order = [
- 'mall_id' => $mall_id,
- 'user_id' => $user_id,
- 'id' => 0
- ];
- $cond_upgrade = new \addons\Agent\common\logic\ConditionUpgrade();
- $cond_uids = $cond_upgrade->execute(AddonsEnum::ADDONS_NAME_AGENT, (new Agent()), (new AgentLevel()), $order);
- return $cond_uids;
- }catch(\Exception $e){
- $exception = FormatHelper::exception($e, 'AgentApply:upgradeLevel err:' . $e->getMessage());
- Yii::error($exception);
- return false;
- }
- }
- }
|