| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- <?php
- namespace addons\AvoidTax\common\models;
- use Yii;
- use yii\data\Pagination;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_tax_ly_silent_sign}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property string $name 真实姓名
- * @property string $phone 手机号码
- * @property string $id_card 身份证
- * @property string $account_id 企业账号ID
- * @property string|null $template_id 企业合同ID
- * @property string|null $email 邮箱
- * @property string|null $callback_url 成功回调链接
- * @property string|null $extra_msg 附加信息
- * @property int $default
- * @property int $status
- * @property string|null $response 响应信息
- * @property int|null $created_at
- * @property int|null $updated_at
- */
- class LySilentSign extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_tax_ly_silent_sign}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'name', 'phone', 'id_card', 'account_id', 'default'], 'required'],
- [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['response'], 'string'],
- [['name', 'phone', 'id_card', 'account_id', 'template_id'], 'string', 'max' => 32],
- [['email', 'account'], 'string', 'max' => 64],
- [['callback_url', 'extra_msg'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'name' => 'Name',
- 'phone' => 'Phone',
- 'id_card' => 'Id Card',
- 'account_id' => 'Account ID',
- 'template_id' => 'Template ID',
- 'email' => 'Email',
- 'callback_url' => 'Callback Url',
- 'extra_msg' => 'Extra Msg',
- 'default' => 'Default',
- 'status' => 'Status',
- 'response' => 'Response',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- /**
- * 获取分页数据
- *
- * @param integer $page
- * @param integer $limit
- * @param callable $callback
- * @param string $order_by
- * @return array
- */
- public static function getPageList(
- int $page, int $limit, callable $callback, string $order_by = 'id'
- ) :array
- {
- $model = static::find();
- if (!empty($callback)) call_user_func($callback, $model);
- $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]);
- $model->limit($pagination->limit)->offset($pagination->offset);
- $list = $model->asArray()->orderBy($order_by)->all();
- $data['list'] = $list;
- $data['page_count'] = $pagination->pageCount;
- $data['current_page'] = $page + 1;
- return $data;
- }
- /**
- * ID查询
- *
- * @param integer $mall_id
- * @param integer $id
- * @return LySilentSign|array|null a single row of query result. Depending on the setting of [[asArray]],
- */
- public static function getUserByIdAndMallId(int $mall_id, int $id)
- {
- return static::find()
- ->where(['mall_id' => $mall_id, 'id' => $id])
- ->one();
- }
- /**
- * 修改账号
- *
- * @param string $mobile
- * @param string|null $account
- * @return boolean
- */
- public function changeMobile(string $mobile, $account = '')
- {
- $this->phone = $mobile;
- $this->account = $account;
- return $this->save();
- }
- /**
- * 添加电签记录
- *
- * @param integer $mall_id
- * @param integer $user_id
- * @param string $name
- * @param string $phone
- * @param string $id_card
- * @param string $account_id
- * @param array $response
- * @param string|null $template_id
- * @param string|null $email
- * @param string|null $callback_url
- * @param string|null $extra_msg
- * @return boolean
- */
- public static function addSilentSign(
- int $mall_id,
- int $user_id,
- string $name,
- string $phone,
- string $id_card,
- string $account_id,
- array $response,
- string $template_id = null,
- string $email = null,
- string $callback_url = null,
- string $extra_msg = null
- )
- {
- $model = new static;
- $model->mall_id = $mall_id;
- $model->user_id = $user_id;
- $model->name = $name;
- $model->phone = $phone;
- $model->id_card = $id_card;
- $model->account_id = $account_id;
- $model->response = Json::encode($response);
- $model->template_id = $template_id;
- $model->email = $email;
- $model->callback_url = $callback_url;
- $model->extra_msg = $extra_msg;
- $model->default = (int)static::isSetDefault($user_id);
- $model->status = $model->checkStatus();
- return $model->save();
- }
- /**
- * 查询是否设置默认
- *
- * @param integer $uid
- * @return boolean
- */
- public static function isSetDefault(int $uid)
- {
- return static::find()->where(['user_id' => $uid, 'status' => 1])->count() > 0
- ? false
- : true;
- }
- /**
- * 获取该用户是否签约
- *
- * @param integer $user_id
- * @return boolean
- */
- public static function getUserIsSign(int $user_id)
- {
- return static::find()
- ->where(['user_id' => $user_id, 'status' => 1])
- ->select('id')
- ->one() ? true : false;
- }
- /**
- * 获取签约用户信息
- *
- * @param integer $user_id
- * @return LySilentSign|array|null
- */
- public static function getSignUser(int $user_id)
- {
- return static::find()
- ->where(['user_id' => $user_id, 'status' => 1])
- ->one();
- }
- /**
- * 身份信息获取
- *
- * @param integer $mall_id
- * @param string $idcard
- * @param string $name
- * @return LySilentSign|array|null
- */
- public static function getAutnByIdcardAndName(int $mall_id, string $idcard, string $name)
- {
- return static::find()
- ->where(['id_card' => $idcard, 'name' => $name, 'mall_id' => $mall_id, 'status' => 1])
- ->one();
- }
- /**
- * uid是否签约
- *
- * @param integer $mall_id
- * @param integer $uid
- * @return boolean
- */
- public static function uidIsSign(int $mall_id, int $uid)
- {
- return static::find()
- ->select('id')
- ->where(['user_id' => $uid, 'mall_id' => $mall_id, 'status' => 1])
- ->one() ? true : false;
- }
- /**
- * 创建一条新的认证记录
- *
- * @param integer $user_id
- * @return boolean
- */
- public function createNewAuth(int $user_id, string $mobile)
- {
- $model = new static;
- $model->user_id = $user_id;
- $model->mall_id = $this->mall_id;
- $model->name = $this->name;
- $model->phone = $mobile;
- $model->id_card = $this->id_card;
- $model->account_id = $this->account_id;
- $model->template_id = $this->template_id;
- $model->email = $this->email;
- $model->callback_url = $this->callback_url;
- $model->extra_msg = $this->extra_msg;
- $model->default = (int)static::isSetDefault($user_id);
- $model->status = $this->status;
- $model->response = $this->response;
- return $model->save();
- }
- /**
- * @return integer
- */
- private function checkStatus()
- {
- $response = Json::decode($this->response);
- if ($response['code'] == '0000') {
- return 1;
- }
- if ($response['code'] == '200' && !empty($response['data']) && $response['data']['status'] == 1) {
- return 1;
- }
- return 0;
- }
- /**
- * 获取用户的认证列表
- *
- * @param integer $mall_id
- * @param integer $user_id
- * @return array|static[]
- */
- public static function getUserAuthList(int $mall_id, int $user_id)
- {
- return static::find()
- ->where(['mall_id' => $mall_id, 'user_id' => $user_id, 'status' => 1])
- ->select(['id', 'mall_id', 'user_id', 'name', 'phone as mobile', 'id_card', 'default'])
- ->asArray()
- ->all();
- }
- /**
- * 获取
- *
- * @param integer $mall_id
- * @param integer $id
- * @return static|null
- */
- public static function getAuthById(int $mall_id, int $id)
- {
- return static::find()
- ->where(['mall_id' => $mall_id, 'id' => $id])
- ->one();
- }
- /**
- * @param integer $mall_id
- * @param integer $user_id
- * @return boolean
- */
- public static function setNotDefault(int $mall_id, int $user_id)
- {
- return static::updateAll(
- ['default' => 0],
- ['mall_id' => $mall_id, 'user_id' => $user_id, 'status' => 1]
- );
- }
- /**
- * @return boolean
- */
- public function setDefault()
- {
- $this->default = 1;
- return $this->save();
- }
- /**
- * 获取默认的签约信息
- *
- * @param integer $mall_id
- * @param integer $user_id
- * @return static|null
- */
- public static function getDefaultSignInfo(int $mall_id, int $user_id)
- {
- return static::find()
- ->select(['id', 'mall_id', 'user_id', 'name', 'phone as mobile', 'account', 'id_card', 'default'])
- ->where(['mall_id' => $mall_id, 'user_id' => $user_id, 'status' => 1, 'default' => 1])
- ->asArray()
- ->one();
- }
- /**
- * 通过name mobile idcard获取用户已签约信息
- *
- * @param integer $user_id
- * @param string $name
- * @param string $mobile
- * @param string $idcard
- * @return static|null
- */
- public static function getSignByNMI(int $user_id, string $name, string $mobile, string $idcard)
- {
- return static::find()
- ->where([
- 'user_id' => $user_id,
- 'name' => $name,
- 'phone' => $mobile,
- 'id_card' => $idcard,
- 'status' => 1
- ])
- ->one();
- }
- /**
- * 查询用户是否有通过名字手机身份证签约
- *
- * @param integer $uid
- * @param string $name
- * @param string $mobile
- * @param string $idcard
- * @return boolean
- */
- public static function userIsSignByNMI(int $uid, string $name, string $mobile, string $idcard)
- {
- return !empty(
- static::find()
- ->where(['user_id' => $uid, 'name' => $name, 'phone' => $mobile, 'id_card' => $idcard])
- ->select('id')
- ->one()
- ) ? true : false;
- }
- /**
- * 获取用户签约信息
- *
- * @param integer $user_id
- * @param integer $id
- * @return static|null
- */
- public static function getSignById(int $user_id, int $id)
- {
- return static::find()
- ->where(['user_id' => $user_id, 'id' => $id, 'status' => 1])
- ->one();
- }
- /**
- * 获取签约成功详情
- *
- * @param integer $mall_id
- * @param integer $id
- * @return static|null
- */
- public static function getOkAuthById(int $mall_id, int $id)
- {
- return static::find()
- ->where(['mall_id' => $mall_id, 'id' => $id, 'status' => 1])
- ->one();
- }
- /**
- * 设置解约状态
- *
- * @return boolean
- */
- public function setLift()
- {
- $this->status = 2;
- return $this->save();
- }
- }
|