| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace addons\Purchase\common\models;
- use addons\Store\common\models\Store;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_purchase_manager}}".
- *
- * @property int $id
- * @property int|null $mall_id 商城ID
- * @property int|null $user_id 会员ID
- * @property int|null $mobile 手机号码
- * @property string|null $license 营业执照
- * @property string|null $store_info 店铺抬头
- * @property string|null $idcart_front 身份证照(正)
- * @property string|null $idcart_back 身份证照(反)
- * @property string|null $idcart_hands 身份证照(手持)
- * @property int $is_poss 审核状态[0审核中 1审核通过 -1拒绝]
- * @property string|null $reason 失败原因
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class PurchaseManager extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_purchase_manager}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'mobile', 'is_poss', 'status', 'created_at', 'updated_at'], 'integer'],
- [['license', 'store_info', 'idcart_front', 'idcart_back', 'idcart_hands', 'reason'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '会员ID',
- 'mobile' => '手机号码',
- 'license' => '营业执照',
- 'store_info' => '店铺抬头',
- 'idcart_front' => '身份证照(正)',
- 'idcart_back' => '身份证照(反)',
- 'idcart_hands' => '身份证照(手持)',
- 'is_poss' => '审核状态[0审核中 1审核通过 -1拒绝]',
- 'reason' => '失败原因',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- ];
- }
- /**
- * @notes:关联用户
- * @return \yii\db\ActiveQuery
- * @author: lun
- * @Time: 2022/10/22 17:45
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,avatar_url');
- }
- /**
- * @notes:数据保存
- * @param $mall_id
- * @param $params
- * @return bool
- * @author: lun
- * @Time: 2022/10/22 18:28
- */
- public static function setData($mall_id, $params)
- {
- $trans = Yii::$app->db->beginTransaction();
- try{
- $model = self::find()->where(['mall_id' => $mall_id, 'user_id' => $params['user_id']])->andWhere(['<>','status',StatusEnum::DELETE])->one();
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $mall_id;
- $model->is_poss = StatusEnum::DISABLED;
- $model->loadDefaultValues();
- unset($params['is_poss']);
- } else {
- // 非首次审核处理
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- $trans->commit();
- return $model->toArray();
- }catch(\Exception $e){
- $trans->rollBack();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @notes:驳回,同意,删除处理
- * @param $mall_id
- * @param $params
- * @return bool
- * @author: lun
- * @Time: 2022/10/22 18:27
- */
- public static function handle($mall_id, $params)
- {
- $trans = Yii::$app->db->beginTransaction();
- try{
- $model = self::findOne(['mall_id' => $mall_id, 'id' => $params['id']]);
- if (empty($model)) throw new \Exception('该用户数据不存在');
- if (!empty($params['is_poss'])) {
- $model->is_poss = $params['is_poss'];
- $params['is_poss'] == StatusEnum::ENABLED && $model->reason = '';
- $params['is_poss'] == StatusEnum::DELETE && $params['reason'] && $model->reason = $params['reason'];
- }
- if (!empty($params['status'])) $model->status = $params['status'];
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- $trans->commit();
- return true;
- }catch(\Exception $e){
- $trans->rollBack();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @notes:检查用户是否审核通过
- * @param $user_id
- * @return bool
- * @author: lun
- * @Time: 2022/10/31 11:32
- */
- public static function check($user_id)
- {
- $data = self::find()->where(['user_id' => $user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if (empty($data)) return false;
- if ($data['is_poss'] != 1) return false;
- return true;
- }
- }
|