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.

3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <?php
  2. namespace common\models;
  3. use common\util\Util;
  4. use fx\util\FxUtil;
  5. use Yii;
  6. use yii\db\ActiveRecord;
  7. use yii\db\Exception;
  8. use yii\db\Expression;
  9. /**
  10. * This is the model class for table "fx_user".
  11. *
  12. * @property integer $uid
  13. * @property string $user_name
  14. * @property string $openid
  15. * @property string $phone
  16. * @property string $nickname
  17. * @property string $headimgurl
  18. * @property integer $sex
  19. * @property string $country
  20. * @property string $province
  21. * @property string $city
  22. * @property integer $status
  23. * @property string $reg_time
  24. * @property integer $delete_flag
  25. * @property string $wx_openid
  26. * @property integer $main_user_id
  27. */
  28. class FxUser extends \yii\db\ActiveRecord
  29. {
  30. /**
  31. * @inheritdoc
  32. */
  33. public static function tableName()
  34. {
  35. return 'fx_user';
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['openid'], 'required'],
  44. [['sex', 'status', 'delete_flag', 'main_user_id', 'change_price_power'], 'integer'],
  45. [['reg_time'], 'safe'],
  46. [['user_name'], 'string', 'max' => 100],
  47. [['openid', 'wx_openid'], 'string', 'max' => 120],
  48. [['phone'], 'string', 'max' => 11],
  49. [['nickname'], 'string', 'max' => 100],
  50. [['headimgurl', 'country', 'province', 'city', 'user_area'], 'string', 'max' => 255],
  51. [['openid'], 'unique'],
  52. ];
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'uid' => 'Uid',
  61. 'user_name' => 'User Name',
  62. 'openid' => 'Openid',
  63. 'phone' => 'Phone',
  64. 'nickname' => 'Nickname',
  65. 'headimgurl' => 'Headimgurl',
  66. 'sex' => 'Sex',
  67. 'country' => 'Country',
  68. 'province' => 'Province',
  69. 'city' => 'City',
  70. 'status' => 'Status',
  71. 'reg_time' => 'Reg Time',
  72. 'delete_flag' => 'Delete Flag',
  73. 'wx_openid' => 'Wx Openid',
  74. 'main_user_id' => 'Main User ID',
  75. 'change_price_power' => 'change_price_power',
  76. 'user_area' => 'user_area'
  77. ];
  78. }
  79. /**
  80. * Function Description:验证是否已注册手机号
  81. * Function Name: checkPhone
  82. *
  83. * @return array
  84. *
  85. * @author 娄梦宁
  86. */
  87. public function checkPhone()
  88. {
  89. $cookies = Yii::$app->request->cookies;
  90. $user_id = $cookies->getValue('user_id');
  91. $phone = self::find()->select('phone')
  92. ->where(['uid' => $user_id])
  93. ->one();
  94. return $phone;
  95. }
  96. /**
  97. * Function Description:注册手机号
  98. * Function Name: registerPhone
  99. * @param $phone
  100. *
  101. * @return bool
  102. *
  103. * @author 娄梦宁
  104. */
  105. public function registerPhone($phone)
  106. {
  107. $values = [
  108. 'phone' => $phone
  109. ];
  110. $base_one = self::findOne(['uid' => FxUtil::$uid, 'delete_flag' => 0]);
  111. $req = "/^.*[0-9a-zA-Z_\x{4e00}-\x{9fa5}].*$/u";
  112. if (Util::checkPattern('', $base_one->nickname, $req) == false) {//如果用户名是空则用户名设置为手机号
  113. $values['nickname'] = $phone;
  114. }
  115. $base_one->attributes = $values;
  116. $res = $base_one->update();
  117. if ($res === false) {
  118. return false;
  119. }
  120. return true;
  121. }
  122. /**
  123. * Des:根据openid获取用户ID
  124. * Name: getUidByOpenid
  125. * @param $openid
  126. * @return mixed|string
  127. * @author 倪宗锋
  128. */
  129. public function getInfoByOpenid($openid)
  130. {
  131. $getUserInfo = self::find()->select(['uid', 'phone', 'status'])
  132. ->where(array('openid' => $openid))
  133. ->asArray(true)
  134. ->one();
  135. if ($getUserInfo == null) {
  136. return '';
  137. }
  138. return $getUserInfo;
  139. }
  140. /**
  141. * Des:添加用户信息
  142. * Name: addUserFromWeChat
  143. * @param $params
  144. * @return bool
  145. * @throws \Exception
  146. * @throws bool
  147. * @author 倪宗锋
  148. */
  149. public function addUserFromWeChat($params)
  150. {
  151. $this->setAttributes($params);
  152. $return = $this->insert(true);
  153. return $return;
  154. }
  155. /**
  156. * Des:获取用户信息
  157. * Name: getUserInfoByUid
  158. * @param $uid
  159. * @return array|null|string|ActiveRecord
  160. * @author 倪宗锋
  161. */
  162. public function getUserInfoByUid($uid)
  163. {
  164. $userInfo = self::find()
  165. ->where(array('uid' => $uid))
  166. ->asArray(true)
  167. ->one();
  168. if ($userInfo == null) {
  169. return '';
  170. }
  171. return $userInfo;
  172. }
  173. /**
  174. * Function Description:获取分销商列表
  175. * Function Name: getUserList
  176. * @param $param
  177. *
  178. * @return array|\yii\db\ActiveRecord[]
  179. *
  180. * @author 娄梦宁
  181. */
  182. public function getUserList($param)
  183. {
  184. $where = ['and', ['!=', 'phone', '']];
  185. if (empty($param['wechat_name']) == false) {
  186. $where[] = ['like', 'nickname', $param['wechat_name']];
  187. }
  188. if (empty($param['fx_phone']) == false) {
  189. $where[] = ['like', 'phone', $param['fx_phone']];
  190. }
  191. if (empty($param['start_reg_time']) == false) {
  192. $where[] = ['>=', 'reg_time', $param['start_reg_time']];
  193. }
  194. if (empty($param['end_reg_time']) == false) {
  195. $where[] = ['<', 'reg_time', date('Y-m-d', strtotime("{$param['end_reg_time']} +1 day"))];
  196. }
  197. if (empty($param['main_user_id']) == false) {
  198. $where[] = ['=', 'a.main_user_id', $param['main_user_id']];
  199. }
  200. if (empty($param['user_area']) == false) {
  201. $where[] = ['=', 'a.user_area', $param['user_area']];
  202. }
  203. //果运营主体非1或空,则读取自身对应的订单数据,如果运营主体为空,或者运营主体是1则读取订单运营主体是0或1的订单
  204. $cookies = $_COOKIE;
  205. if (empty($cookies['user_main_corp']) == false && $cookies['user_main_corp'] != 1 && in_array(YII_ENV,['pro','dev'])) {
  206. $where[] = ['=', 'e.main_corp_id', $cookies['user_main_corp']];
  207. }
  208. $offset = ($param['current_page'] - 1) * $param['page_size'];
  209. $select = [
  210. 'a.uid as fx_uid',
  211. new Expression('FORMAT(b.remaining_sum,0) as remaining_sum'),
  212. 'a.nickname as wechat_name',
  213. "ifnull(a.user_name,'') user_name",
  214. 'a.phone as fx_phone',
  215. 'a.reg_time',
  216. 'b.status as fx_status_id',
  217. "if(b.status=1,'已启用','未启用') as fx_status",
  218. 'ifnull(b.total_commission,0) as total_commission',
  219. 'ifnull(b.closed_commission,0) as closed_commission',
  220. 'ifnull(b.available_commission,0) available_commission',
  221. 'change_price_power' => new Expression("SUBSTR(change_price_power FROM 1 FOR 1)"),//巴士自由行的改价权限
  222. 'change_price_power_hotel' => new Expression("SUBSTR(change_price_power FROM 2 FOR 1)"),//酒店的改价权限
  223. 'main_user_name' => new Expression("ifnull((SELECT user_name from main_corp_user WHERE id= a.main_user_id),'')"),
  224. 'main_corp_name' => new Expression("ifnull((SELECT main_corp_name from main_corp_user WHERE id= a.main_user_id),'')"),
  225. 'user_area' => new Expression("ifnull((SELECT GROUP_CONCAT(area_name SEPARATOR '</br>') from fx_user_area WHERE FIND_IN_SET(area_id,a.user_area)),'')")
  226. ];
  227. $result = self::find()->select($select)
  228. ->from(self::tableName() . ' as a')
  229. ->innerJoin('fx_user_account as b', ' b.fx_uid=a.uid')
  230. ->leftJoin(MainCorpUser::tableName() . ' e', 'a.main_user_id = e.id')
  231. ->where($where)
  232. ->orderBy('a.reg_time desc')
  233. ->offset($offset)
  234. ->limit($param['page_size'])
  235. ->asArray()
  236. ->all();
  237. $result1 = self::find()->select('count(1) as count')
  238. ->from(self::tableName() . ' as a')
  239. ->innerJoin('fx_user_account as b', ' b.fx_uid=a.uid')
  240. ->leftJoin(MainCorpUser::tableName() . ' e', 'a.main_user_id = e.id')
  241. ->asArray()
  242. ->where($where)
  243. ->one();
  244. $result1 = $result1['count'];
  245. return ['list' => $result,
  246. 'count' => $result1
  247. ];
  248. }
  249. /*
  250. * 分销商审核列表
  251. */
  252. public function CheckFxUser($param)
  253. {
  254. $where = ['and', ['=', 'a.delete_flag', '0']];
  255. if ($param['wechat_name'] != '') {
  256. $where[] = ['like', 'a.nickname', $param['wechat_name']];
  257. }
  258. if ($param['fx_phone'] != '') {
  259. $where[] = ['like', 'a.phone', $param['fx_phone']];
  260. }
  261. if ($param['start_reg_time'] != '') {
  262. $where[] = ['>=', 'a.reg_time', $param['start_reg_time']];
  263. }
  264. if ($param['end_reg_time'] != '') {
  265. $where[] = ['<', 'a.reg_time', date('Y-m-d', strtotime("{$param['end_reg_time']} +1 day"))];
  266. }
  267. if ($param['status'] != '') {
  268. $where[] = ['=', 'a.status', $param['status']];
  269. }
  270. if (empty($param['main_user_id']) == false) {
  271. $where[] = ['=', 'a.main_user_id', $param['main_user_id']];
  272. }
  273. if (empty($param['user_area']) == false) {
  274. $where[] = ['=', 'a.user_area', $param['user_area']];
  275. }
  276. //果运营主体非1或空,则读取自身对应的订单数据,如果运营主体为空,或者运营主体是1则读取订单运营主体是0或1的订单
  277. $cookies = $_COOKIE;
  278. if (empty($cookies['user_main_corp']) == false && !in_array($cookies['user_main_corp'], [1, 34])) {
  279. $where[] = ['=', 'e.main_corp_id', $cookies['user_main_corp']];
  280. }
  281. $offset = ($param['current_page'] - 1) * $param['page_size'];
  282. $select = [
  283. 'a.nickname',
  284. "ifnull(a.user_name,'') user_name",
  285. 'a.phone',
  286. 'a.reg_time',
  287. "if(a.status = 1,'审核未通过',if(a.status=2,'审核通过','待审核')) as status_type",
  288. 'a.uid as fx_uid',
  289. 'a.status',
  290. 'main_user_name' => new Expression("ifnull((SELECT user_name from main_corp_user WHERE id= a.main_user_id),'')"),
  291. 'main_corp_name' => new Expression("ifnull((SELECT main_corp_name from main_corp_user WHERE id= a.main_user_id),'')")
  292. ];
  293. $result = self::find()->select($select)
  294. ->from(self::tableName() . ' a')
  295. ->leftJoin(MainCorpUser::tableName() . ' e', 'a.main_user_id = e.id')
  296. ->where($where)
  297. ->orderBy('a.reg_time desc')
  298. ->offset($offset)
  299. ->limit($param['page_size'])
  300. ->asArray()
  301. ->all();
  302. $result1 = self::find()->select('count(1) as count')
  303. ->from(self::tableName() . ' a')
  304. ->leftJoin(MainCorpUser::tableName() . ' e', 'a.main_user_id = e.id')
  305. ->asArray()
  306. ->where($where)
  307. ->one();
  308. $result1 = $result1['count'];
  309. return ['list' => $result,
  310. 'count' => $result1
  311. ];
  312. }
  313. /*
  314. * 分销商审核通过
  315. */
  316. public function ThroughFxUser($fx_uid, $status)
  317. {
  318. $count = self::updateAll(['status' => $status], ['=', 'uid', $fx_uid]);
  319. return $count;
  320. }
  321. /**
  322. * Des:修改用户名
  323. * Name: updateUserName
  324. * @param $fx_uid
  325. * @param $user_name
  326. * @return int
  327. * @author 倪宗锋
  328. */
  329. public function updateUserName($fx_uid, $user_name)
  330. {
  331. $count = self::updateAll(['user_name' => $user_name], ['=', 'uid', $fx_uid]);
  332. return $count;
  333. }
  334. /**
  335. * Des:绑定运维负责人
  336. * Name: updateUserName
  337. * @param $fx_uid
  338. * @param $main_user_id
  339. * @return int
  340. * @author 倪宗锋
  341. */
  342. public function bindMainCorp($fx_uid, $main_user_id)
  343. {
  344. $count = self::updateAll(['main_user_id' => $main_user_id], ['=', 'uid', $fx_uid]);
  345. return $count;
  346. }
  347. /**
  348. * Des:获取用户详细
  349. * Name: getUserInfo
  350. * @param $fx_uid
  351. * @return array|null|ActiveRecord
  352. * @author 倪宗锋
  353. */
  354. public function getUserInfo($fx_uid)
  355. {
  356. $select = [
  357. 'a.uid',
  358. 'a.nickname',
  359. 'a.phone',
  360. 'a.main_user_id',
  361. 'b.id',
  362. 'b.user_name',
  363. 'b.main_corp_id',
  364. 'b.main_corp_name',
  365. 'a.user_area'
  366. ];
  367. $info = self::find()->select($select)
  368. ->from(static::tableName() . ' a')
  369. ->leftJoin(MainCorpUser::tableName() . ' b', 'a.main_user_id = b.id')
  370. ->where(['=', 'a.uid', $fx_uid])
  371. ->asArray()
  372. ->one();
  373. return $info;
  374. }
  375. /**
  376. * Function Description:修改用户改价权限
  377. * Function Name: uptChangePricePower
  378. * @param $fx_uid
  379. * @param $change_price_power
  380. * @param $type
  381. *
  382. * @return bool
  383. *
  384. * @author 娄梦宁
  385. */
  386. public function uptChangePricePower($fx_uid, $change_price_power, $type)
  387. {
  388. // print_r([$type,$change_price_power,$change_price_power]);die;
  389. try {
  390. self::updateAll(['change_price_power' => new Expression("INSERT(change_price_power,$type,1,$change_price_power)")], ['=', 'uid', $fx_uid]);
  391. return true;
  392. } catch (Exception $e) {
  393. return false;
  394. }
  395. }
  396. /**
  397. * Des:修改用户名
  398. * Name: updateUserName
  399. * @param $fx_uid
  400. * @param $userArea
  401. * @return int
  402. * @author 倪宗锋
  403. */
  404. public function updateUserArea($fx_uid, $userArea)
  405. {
  406. $count = self::updateAll(['user_area' => $userArea], ['=', 'uid', $fx_uid]);
  407. return $count;
  408. }
  409. }