|
- <?php
- /**
- * 数据库表类 fx_user_openid
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2017/07/31 10:20 $
- */
-
- namespace common\models;
-
- use common\util\Util;
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * 数据库表类 fx_user_openid.
- * @property integer $id
- * @property string $open_id
- * @property integer $fx_uid
- * @property string $reg_time
- */
- class FxUserOpenid extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'fx_user_openid';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['open_id'], 'required'],
- [['fx_uid'], 'integer'],
- [['reg_time'], 'safe'],
- [['open_id'], 'string', 'max' => 255],
- [['open_id'], 'unique'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'open_id' => 'Open ID',
- 'fx_uid' => 'Fx Uid',
- 'reg_time' => 'Reg Time',
- ];
- }
-
- /**
- * Des:根据openid获取fx_uid
- * Name: getFxUidByOpenId
- * @param $openId
- * @return bool|mixed
- * @author 倪宗锋
- */
- public function getFxUidByOpenId($openId)
- {
- $select = [
- 'fx_uid' => new Expression("if(ifnull(b.fx_uid,0)=0,a.fx_uid,b.fx_uid)")
- ];
- $result = self::find()->select($select)
- ->from(self::tableName() . ' a')
- ->leftJoin(FxUserQrcode::tableName() . ' b', 'a.fx_uid=b.qr_id')
- ->where(['=', 'a.open_id', $openId])
- ->asArray()
- ->one();
- if (isset($result['fx_uid']) && $result['fx_uid']) {
- return $result['fx_uid'];
- }
- return false;
- }
-
- /**
- * @param $openid
- * @param $from_qrcode_id
- * @throws \yii\db\Exception
- */
- public function editFxWeChatFxUid($openid, $from_qrcode_id)
- {
- $from_qrcode_id = $from_qrcode_id - 50000;
- $sql = "replace into fx_user_openid(open_id,fx_uid) VALUES('{$openid}',{$from_qrcode_id})";
- $this->getDb()->createCommand($sql)->execute();
- }
- }
|