My.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use Api\Express;
  13. use app\admin\model\system\SystemAdmin;
  14. use app\admin\model\system\SystemConfig;
  15. use app\wap\model\activity\EventSignUp;
  16. use app\wap\model\special\SpecialRecord;
  17. use app\wap\model\special\SpecialRelation;
  18. use app\wap\model\user\SmsCode;
  19. use app\wap\model\special\Grade;
  20. use app\wap\model\store\StoreOrderCartInfo;
  21. use app\wap\model\store\StorePink;
  22. use app\wap\model\store\StoreProduct;
  23. use app\wap\model\store\StoreProductRelation;
  24. use app\wap\model\store\StoreOrder;
  25. use app\wap\model\user\PhoneUser;
  26. use app\wap\model\user\User;
  27. use app\wap\model\user\UserBill;
  28. use app\wap\model\user\UserExtract;
  29. use app\wap\model\user\UserAddress;
  30. use app\wap\model\user\UserSign;
  31. use service\CacheService;
  32. use service\GroupDataService;
  33. use service\JsonService;
  34. use service\SystemConfigService;
  35. use service\UtilService;
  36. use think\Cookie;
  37. use think\Request;
  38. use think\Session;
  39. use think\Url;
  40. class My extends AuthController
  41. {
  42. /*
  43. * 白名单
  44. * */
  45. public static function WhiteList()
  46. {
  47. return [
  48. 'index',
  49. 'about_us'
  50. ];
  51. }
  52. /**
  53. * 退出手机号码登录
  54. */
  55. public function logout()
  56. {
  57. Cookie::delete('__login_phone');
  58. Session::delete('__login_phone_num' . $this->uid, 'wap');
  59. Session::delete('loginUid', 'wap');
  60. return JsonService::successful('已退出登录');
  61. }
  62. public function my_gift()
  63. {
  64. return $this->fetch();
  65. }
  66. public function sign_list()
  67. {
  68. return $this->fetch();
  69. }
  70. public function sign_order($type=1,$order_id='')
  71. {
  72. $order=EventSignUp::where('order_id',$order_id)->where('paid',1)->find();
  73. if(!$order) return $this->redirect(Url::build('sign_list'));
  74. if($type==2){
  75. $res=SystemAdmin::testUserLevel($this->userInfo);
  76. if(!$res) return $this->redirect(Url::build('wap/my/index'));
  77. }
  78. $this->assign(['type'=>$type,'order_id'=>$order_id,'status'=>$order['status']]);
  79. return $this->fetch('order_verify');
  80. }
  81. public function get_my_gift_list()
  82. {
  83. return $this->fetch();
  84. }
  85. public function user_info()
  86. {
  87. return $this->fetch();
  88. }
  89. public function validate_code()
  90. {
  91. list($phone, $code,) = UtilService::getMore([
  92. ['phone', ''],
  93. ['code', ''],
  94. ], $this->request, true);
  95. if (!$phone) return JsonService::fail('请输入手机号码');
  96. if (!$code) return JsonService::fail('请输入验证码');
  97. if (!SmsCode::CheckCode($phone, $code)) return JsonService::fail('验证码验证失败');
  98. SmsCode::setCodeInvalid($phone, $code);
  99. return JsonService::successful('验证成功');
  100. }
  101. public function get_grade()
  102. {
  103. return JsonService::successful(Grade::getPickerData());
  104. }
  105. public function save_user_info()
  106. {
  107. $data = UtilService::postMore([
  108. ['avatar', ''],
  109. ['nickname', ''],
  110. ['grade_id', 0]
  111. ], $this->request);
  112. if($data['nickname'] != strip_tags($data['nickname'])){
  113. $data['nickname'] = htmlspecialchars($data['nickname']);
  114. }
  115. if (!$data['nickname']) return JsonService::fail('用户昵称不能为空');
  116. if (User::update($data, ['uid' => $this->uid]))
  117. return JsonService::successful('保存成功');
  118. else
  119. return JsonService::fail('保存失败');
  120. }
  121. /**
  122. * 保存手机号码
  123. * @return mixed|void
  124. * @throws \think\db\exception\DataNotFoundException
  125. * @throws \think\db\exception\ModelNotFoundException
  126. * @throws \think\exception\DbException
  127. * @throws \think\exception\PDOException
  128. */
  129. public function save_phone()
  130. {
  131. if ($this->request->isAjax()) {
  132. list($phone, $code, $type) = UtilService::getMore([
  133. ['phone', ''],
  134. ['code', ''],
  135. ['type', 0],
  136. ], $this->request, true);
  137. if (!$phone) return JsonService::fail('请输入手机号码');
  138. if (!$code) return JsonService::fail('请输入验证码');
  139. if (!SmsCode::CheckCode($phone, $code)) return JsonService::fail('验证码验证失败');
  140. SmsCode::setCodeInvalid($phone, $code);
  141. $user=User::where(['phone' => $phone, 'is_h5user' => 0])->find();
  142. if($type && $user){
  143. if($user['uid']==$this->uid){
  144. return JsonService::fail('不能绑定相同手机号');
  145. }else if($user['uid']!=$this->uid){
  146. return JsonService::fail('当前手机号码已绑定微信用户');
  147. }
  148. }else if($type==0 && $user){
  149. if($user) return JsonService::fail('当前手机号码已绑定微信用户');
  150. }
  151. //查找H5手机号码账户
  152. $phoneUser = PhoneUser::where(['phone' => $phone])->find();
  153. //H5页面有注册过
  154. if ($phoneUser && $phoneUser['uid']!=$this->uid) {
  155. //检测当前用户是否是H5用户
  156. if (User::where('uid', $phoneUser['uid'])->value('is_h5user')) {
  157. $res = User::setUserRelationInfos($phone, $phoneUser['uid'], $this->uid);
  158. if ($res === false) return JsonService::fail(User::getErrorInfo());
  159. }
  160. }else if($phoneUser && $phoneUser['uid']==$this->uid){
  161. return JsonService::fail('不能绑定相同手机号');
  162. }
  163. if (!isset($res)) User::update(['phone' => $phone], ['uid' => $this->uid]);
  164. return JsonService::successful('绑定成功');
  165. } else {
  166. $this->assign('user_phone', $this->userInfo['phone']);
  167. return $this->fetch();
  168. }
  169. }
  170. /**
  171. * 个人中心
  172. * @return mixed
  173. * @throws \think\Exception
  174. */
  175. public function index()
  176. {
  177. $store_brokerage_statu=SystemConfigService::get('store_brokerage_statu');
  178. if($store_brokerage_statu==1){
  179. $is_statu=$this->userInfo['is_promoter'] >0 ? 1 : 0;
  180. }else if($store_brokerage_statu==2){
  181. $is_statu=1;
  182. }
  183. $this->assign([
  184. 'gold_name'=>SystemConfigService::get('gold_name'),
  185. 'collectionNumber' => SpecialRelation::where('uid', $this->uid)->count(),
  186. 'recordNumber' => SpecialRecord::where('uid', $this->uid)->count(),
  187. 'overdue_time'=>date('Y-m-d',$this->userInfo['overdue_time']),
  188. 'is_statu'=>$is_statu
  189. ]);
  190. return $this->fetch();
  191. }
  192. /**虚拟币明细
  193. * @return mixed
  194. */
  195. public function gold_coin(){
  196. $gold_name=SystemConfigService::get('gold_name');//虚拟币名称
  197. $this->assign(compact('gold_name'));
  198. return $this->fetch('coin_detail');
  199. }
  200. /**签到
  201. * @return mixed
  202. */
  203. public function sign_in()
  204. {
  205. $urls=SystemConfigService::get('site_url').'/';
  206. $gold_name=SystemConfigService::get('gold_name');//虚拟币名称
  207. $gold_coin=SystemConfigService::get('single_gold_coin');//签到获得虚拟币
  208. $signed = UserSign::checkUserSigned($this->userInfo['uid']);//今天是否签到
  209. $sign_image = $urls."uploads/" . "poster_sign_" .$this->userInfo['uid'] . ".png";
  210. $signCount = UserSign::userSignedCount($this->userInfo['uid']);//累记签到天数
  211. $this->assign(compact('signed', 'signCount', 'gold_name','gold_coin', 'sign_image'));
  212. return $this->fetch();
  213. }
  214. /**签到明细
  215. * @return mixed
  216. */
  217. public function sign_in_list(){
  218. return $this->fetch();
  219. }
  220. public function collect()
  221. {
  222. return $this->fetch();
  223. }
  224. /**地址列表
  225. * @return mixed
  226. */
  227. public function address()
  228. {
  229. $address=UserAddress::getUserValidAddressList($this->userInfo['uid'], 'id,real_name,phone,province,city,district,detail,is_default');
  230. $this->assign([
  231. 'address' => json_encode($address)
  232. ]);
  233. return $this->fetch();
  234. }
  235. /**修改或添加地址
  236. * @param string $addressId
  237. * @return mixed
  238. * @throws \think\Exception
  239. * @throws \think\db\exception\DataNotFoundException
  240. * @throws \think\db\exception\ModelNotFoundException
  241. * @throws \think\exception\DbException
  242. */
  243. public function edit_address($addressId = '',$cartId=0)
  244. {
  245. if ($addressId && is_numeric($addressId) && UserAddress::be(['is_del' => 0, 'id' => $addressId, 'uid' => $this->userInfo['uid']])) {
  246. $addressInfo = UserAddress::find($addressId)->toArray();
  247. } else {
  248. $addressInfo = [];
  249. }
  250. $addressInfo = json_encode($addressInfo);
  251. $this->assign(compact('addressInfo','cartId'));
  252. return $this->fetch();
  253. }
  254. public function recharge()
  255. {
  256. return $this->fetch();
  257. }
  258. /**订单详情
  259. * @param string $uni
  260. * @return mixed|void
  261. */
  262. public function order($uni = '')
  263. {
  264. if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $uni)) return $this->redirect(Url::build('order_list'));
  265. $this->assign([
  266. 'order' => StoreOrder::tidyOrder($order, true)
  267. ]);
  268. return $this->fetch();
  269. }
  270. public function orderPinkOld($uni = '')
  271. {
  272. if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $uni)) return $this->redirect(Url::build('order_list'));
  273. $this->assign([
  274. 'order' => StoreOrder::tidyOrder($order, true)
  275. ]);
  276. return $this->fetch('order');
  277. }
  278. /**获取订单
  279. * @param int $type
  280. * @param int $page
  281. * @param int $limit
  282. * @throws \think\Exception
  283. * @throws \think\db\exception\DataNotFoundException
  284. * @throws \think\db\exception\ModelNotFoundException
  285. * @throws \think\exception\DbException
  286. */
  287. public function get_order_list($type = -1, $page = 1, $limit = 10)
  288. {
  289. return JsonService::successful(StoreOrder::getSpecialOrderList((int)$type, (int)$page, (int)$limit, $this->uid));
  290. }
  291. /**我的拼课订单
  292. * @return mixed
  293. */
  294. public function order_list()
  295. {
  296. return $this->fetch();
  297. }
  298. /**申请退款
  299. * @param string $order_id
  300. * @return mixed
  301. */
  302. public function refund_apply($order_id='')
  303. {
  304. if (!$order_id || !$order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $order_id)) return $this->redirect(Url::build('order_list'));
  305. $this->assign([
  306. 'order' => StoreOrder::tidyOrder($order, true,true),
  307. 'order_id'=>$order_id
  308. ]);
  309. return $this->fetch();
  310. }
  311. public function order_reply($unique = '')
  312. {
  313. if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return $this->failed('评价产品不存在!');
  314. $this->assign(['cartInfo' => $cartInfo]);
  315. return $this->fetch();
  316. }
  317. public function balance()
  318. {
  319. $this->assign([
  320. 'userMinRecharge' => SystemConfigService::get('store_user_min_recharge')
  321. ]);
  322. return $this->fetch();
  323. }
  324. public function spread_list()
  325. {
  326. $statu = (int)SystemConfig::getValue('store_brokerage_statu');
  327. if ($statu == 1) {
  328. if (!User::be(['uid' => $this->userInfo['uid'], 'is_promoter' => 1]))
  329. return $this->failed('没有权限访问!', Url::build('my/index'));
  330. }
  331. $this->assign([
  332. 'total' => User::where('spread_uid', $this->userInfo['uid'])->count()
  333. ]);
  334. return $this->fetch();
  335. }
  336. public function notice()
  337. {
  338. return $this->fetch();
  339. }
  340. public function express($uni = '')
  341. {
  342. if (!$uni || !($order = StoreOrder::getUserOrderDetail($this->userInfo['uid'], $uni))) return $this->failed('查询订单不存在!');
  343. if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!');
  344. $cacheName = $uni . $order['delivery_id'];
  345. $result = CacheService::get($cacheName, null);
  346. if ($result === null) {
  347. $result = Express::query($order['delivery_id']);
  348. if (is_array($result) &&
  349. isset($result['result']) &&
  350. isset($result['result']['deliverystatus']) &&
  351. $result['result']['deliverystatus'] >= 3)
  352. $cacheTime = 0;
  353. else
  354. $cacheTime = 1800;
  355. CacheService::set($cacheName, $result, $cacheTime);
  356. }
  357. $this->assign([
  358. 'order' => $order,
  359. 'express' => $result
  360. ]);
  361. return $this->fetch();
  362. }
  363. public function user_pro()
  364. {
  365. $statu = (int)SystemConfig::getValue('store_brokerage_statu');
  366. if ($statu == 1) {
  367. if (!User::be(['uid' => $this->userInfo['uid'], 'is_promoter' => 1]))
  368. return $this->failed('没有权限访问!');
  369. }
  370. $userBill = new UserBill();
  371. $number = $userBill->where('uid', $this->userInfo['uid'])
  372. ->where('add_time', 'BETWEEN', [strtotime('today -1 day'), strtotime('today')])
  373. ->where('category', 'now_money')
  374. ->where('type', 'brokerage')
  375. ->value('SUM(number)') ?: 0;
  376. $allNumber = $userBill
  377. ->where('uid', $this->userInfo['uid'])
  378. ->where('category', 'now_money')
  379. ->where('type', 'brokerage')
  380. ->value('SUM(number)') ?: 0;
  381. $extractNumber = UserExtract::userExtractTotalPrice($this->userInfo['uid']);
  382. $this->assign([
  383. 'number' => $number,
  384. 'allnumber' => $allNumber,
  385. 'extractNumber' => $extractNumber
  386. ]);
  387. return $this->fetch();
  388. }
  389. public function commission()
  390. {
  391. $uid = (int)Request::instance()->get('uid', 0);
  392. if (!$uid) return $this->failed('用户不存在!');
  393. $this->assign(['uid' => $uid]);
  394. return $this->fetch();
  395. }
  396. public function extract()
  397. {
  398. $minExtractPrice = floatval(SystemConfigService::get('user_extract_min_price')) ?: 0;
  399. $extractInfo = UserExtract::userLastInfo($this->userInfo['uid']) ?: [
  400. 'extract_type' => 'bank',
  401. 'real_name' => '',
  402. 'bank_code' => '',
  403. 'bank_address' => '',
  404. 'alipay_code' => ''
  405. ];
  406. $this->assign(compact('minExtractPrice', 'extractInfo'));
  407. return $this->fetch();
  408. }
  409. /**
  410. * 售后服务 退款订单
  411. * @return mixed
  412. */
  413. public function order_customer()
  414. {
  415. return $this->fetch();
  416. }
  417. /**
  418. * 关于我们
  419. * @return mixed
  420. */
  421. public function about_us()
  422. {
  423. $this->assign([
  424. 'content' => get_config_content('about_us'),
  425. 'title' => '关于我们'
  426. ]);
  427. return $this->fetch('index/agree');
  428. }
  429. public function getUserGoldBill()
  430. {
  431. $user_info = $this->userInfo;
  432. list($page, $limit) = UtilService::getMore([
  433. ['page', 1],
  434. ['limit', 20],
  435. ], $this->request, true);
  436. $where['uid'] = $user_info['uid'];
  437. $where['category'] = "gold_num";
  438. return JsonService::successful(UserBill::getUserGoldBill($where, $page, $limit));
  439. }
  440. /**
  441. * 余额明细
  442. */
  443. public function bill_detail(){
  444. return $this->fetch();
  445. }
  446. }