You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 rivejä
2.7 KiB

  1. <?php
  2. /**
  3. * 数据库表类 fx_user_openid
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/07/31 10:20 $
  14. */
  15. namespace common\models;
  16. use common\util\Util;
  17. use yii\db\ActiveRecord;
  18. use yii\db\Expression;
  19. /**
  20. * 数据库表类 fx_user_openid.
  21. * @property integer $id
  22. * @property string $open_id
  23. * @property integer $fx_uid
  24. * @property string $reg_time
  25. */
  26. class FxUserOpenid extends ActiveRecord
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return 'fx_user_openid';
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['open_id'], 'required'],
  42. [['fx_uid'], 'integer'],
  43. [['reg_time'], 'safe'],
  44. [['open_id'], 'string', 'max' => 255],
  45. [['open_id'], 'unique'],
  46. ];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'open_id' => 'Open ID',
  56. 'fx_uid' => 'Fx Uid',
  57. 'reg_time' => 'Reg Time',
  58. ];
  59. }
  60. /**
  61. * Des:根据openid获取fx_uid
  62. * Name: getFxUidByOpenId
  63. * @param $openId
  64. * @return bool|mixed
  65. * @author 倪宗锋
  66. */
  67. public function getFxUidByOpenId($openId)
  68. {
  69. $select = [
  70. 'fx_uid' => new Expression("if(ifnull(b.fx_uid,0)=0,a.fx_uid,b.fx_uid)")
  71. ];
  72. $result = self::find()->select($select)
  73. ->from(self::tableName() . ' a')
  74. ->leftJoin(FxUserQrcode::tableName() . ' b', 'a.fx_uid=b.qr_id')
  75. ->where(['=', 'a.open_id', $openId])
  76. ->asArray()
  77. ->one();
  78. if (isset($result['fx_uid']) && $result['fx_uid']) {
  79. return $result['fx_uid'];
  80. }
  81. return false;
  82. }
  83. /**
  84. * @param $openid
  85. * @param $from_qrcode_id
  86. * @throws \yii\db\Exception
  87. */
  88. public function editFxWeChatFxUid($openid, $from_qrcode_id)
  89. {
  90. $from_qrcode_id = $from_qrcode_id - 50000;
  91. $sql = "replace into fx_user_openid(open_id,fx_uid) VALUES('{$openid}',{$from_qrcode_id})";
  92. $this->getDb()->createCommand($sql)->execute();
  93. }
  94. }