UserApi.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <?php
  2. namespace app\ebapi\controller;
  3. use Api\Express;
  4. use app\core\model\user\UserLevel;
  5. use app\core\model\user\UserSign;
  6. use app\core\model\routine\RoutineCode;//待完善
  7. use app\core\model\routine\RoutineFormId;//待完善
  8. use app\ebapi\model\store\StoreBargain;
  9. use app\ebapi\model\store\StoreCombination;
  10. use app\ebapi\model\store\StoreCouponUser;
  11. use app\ebapi\model\store\StoreOrder;
  12. use app\ebapi\model\store\StoreOrderCartInfo;
  13. use app\ebapi\model\store\StoreProductRelation;
  14. use app\ebapi\model\store\StoreProductReply;
  15. use app\ebapi\model\store\StoreSeckill;
  16. use app\ebapi\model\user\User;
  17. use app\ebapi\model\user\UserAddress;
  18. use app\core\model\user\UserBill;
  19. use app\ebapi\model\user\UserExtract;
  20. use app\ebapi\model\user\UserNotice;
  21. use app\ebapi\model\user\UserRecharge;
  22. use service\CacheService;
  23. use app\core\util\GroupDataService;
  24. use service\JsonService;
  25. use app\core\util\SystemConfigService;
  26. use service\UtilService;
  27. use think\Request;
  28. use think\Cache;
  29. /**
  30. * 小程序个人中心api接口
  31. * Class UserApi
  32. * @package app\ebapi\controller
  33. *
  34. */
  35. class UserApi extends AuthController
  36. {
  37. /*
  38. * 获取签到按月份查找
  39. * @param int $page 页码
  40. * @param int $limit 显示条数
  41. * @return json
  42. * */
  43. public function get_sign_month_list($page=1,$limit=10)
  44. {
  45. return JsonService::successful(UserSign::getSignMonthList($this->uid,$page,$limit));
  46. }
  47. /*
  48. * 获取用户签到记录列表
  49. *
  50. * */
  51. public function get_sign_list($page=1,$limit=10)
  52. {
  53. return JsonService::successful(UserSign::getSignList($this->uid,$page,$limit));
  54. }
  55. /*
  56. * 获取当前登录的用户信息
  57. * */
  58. public function get_my_user_info()
  59. {
  60. list($isSgin,$isIntegral,$isall)=UtilService::getMore([
  61. ['isSgin',0],
  62. ['isIntegral',0],
  63. ['isall',0],
  64. ],$this->request,true);
  65. //是否统计签到
  66. if($isSgin || $isall){
  67. $this->userInfo['sum_sgin_day']=UserSign::getSignSumDay($this->uid);
  68. $this->userInfo['is_day_sgin']=UserSign::getToDayIsSign($this->uid);
  69. $this->userInfo['is_YesterDay_sgin']=UserSign::getYesterDayIsSign($this->uid);
  70. if(!$this->userInfo['is_day_sgin'] && !$this->userInfo['is_YesterDay_sgin']){
  71. $this->userInfo['sign_num']=0;
  72. }
  73. }
  74. //是否统计积分使用情况
  75. if($isIntegral || $isall){
  76. $this->userInfo['sum_integral']=(int)UserBill::getRecordCount($this->uid,'integral','sign,system_add,gain');
  77. $this->userInfo['deduction_integral']=(int)UserBill::getRecordCount($this->uid,'integral','deduction') ? : 0;
  78. $this->userInfo['today_integral']=(int)UserBill::getRecordCount($this->uid,'integral','sign,system_add,gain','today');
  79. }
  80. unset($this->userInfo['pwd']);
  81. $this->userInfo['integral']=(int)$this->userInfo['integral'];
  82. if(!$this->userInfo['is_promoter']){
  83. $this->userInfo['is_promoter']=(int)SystemConfigService::get('store_brokerage_statu') == 2 ? true : false;
  84. }
  85. return JsonService::successful($this->userInfo);
  86. }
  87. /**
  88. * 获取用户信息
  89. * @param int $userId 用户uid
  90. * @return \think\response\Json
  91. */
  92. public function get_user_info_uid($userId = 0){
  93. if(!$userId) return JsonService::fail('参数错误');
  94. $res = User::getUserInfo($userId);
  95. if($res) return JsonService::successful($res);
  96. else return JsonService::fail(User::getErrorInfo());
  97. }
  98. /**
  99. * 个人中心
  100. * @return \think\response\Json
  101. */
  102. public function my(){
  103. $this->userInfo['couponCount'] = StoreCouponUser::getUserValidCouponCount($this->userInfo['uid']);
  104. $this->userInfo['like'] = StoreProductRelation::getUserIdCollect($this->userInfo['uid']);;
  105. $this->userInfo['orderStatusNum'] = StoreOrder::getOrderStatusNum($this->userInfo['uid']);
  106. $this->userInfo['notice'] = UserNotice::getNotice($this->userInfo['uid']);
  107. $this->userInfo['brokerage'] = UserBill::getBrokerage($this->uid);//获取总佣金
  108. $this->userInfo['recharge'] = UserBill::getRecharge($this->uid);//累计充值
  109. $this->userInfo['orderStatusSum'] = StoreOrder::getOrderStatusSum($this->uid);//累计消费
  110. $this->userInfo['extractTotalPrice'] = UserExtract::userExtractTotalPrice($this->uid);//累计提现
  111. if($this->userInfo['brokerage'] > $this->userInfo['extractTotalPrice']) {
  112. $this->userInfo['brokerage']=bcsub($this->userInfo['brokerage'],$this->userInfo['extractTotalPrice'],2);//减去已提现金额
  113. $extract_price=UserExtract::userExtractTotalPrice($this->uid,0);
  114. $this->userInfo['brokerage']=$extract_price < $this->userInfo['brokerage'] ? bcsub($this->userInfo['brokerage'],$extract_price,2) : 0;//减去审核中的提现金额
  115. }else{
  116. $this->userInfo['brokerage']=0;
  117. }
  118. $this->userInfo['extractPrice'] = (float)bcsub($this->userInfo['brokerage'],$this->userInfo['extractTotalPrice'],2) > 0 ? : 0;//可提现
  119. $this->userInfo['statu'] = (int)SystemConfigService::get('store_brokerage_statu');
  120. $vipId=UserLevel::getUserLevel($this->uid);
  121. $this->userInfo['vip']=$vipId !==false ? true : false;
  122. if($this->userInfo['vip']){
  123. $this->userInfo['vip_id']=$vipId;
  124. $this->userInfo['vip_icon']=UserLevel::getUserLevelInfo($vipId,'icon');
  125. $this->userInfo['vip_name']=UserLevel::getUserLevelInfo($vipId,'name');
  126. }
  127. unset($this->userInfo['pwd']);
  128. return JsonService::successful($this->userInfo);
  129. }
  130. /**
  131. * 用户签到
  132. * @return \think\response\Json
  133. */
  134. public function user_sign()
  135. {
  136. $signed = UserSign::getToDayIsSign($this->userInfo['uid']);
  137. if($signed) return JsonService::fail('已签到');
  138. if(false !== $integral = UserSign::sign($this->uid))
  139. return JsonService::successful('签到获得'.floatval($integral).'积分',['integral'=>$integral]);
  140. else
  141. return JsonService::fail(UserSign::getErrorInfo('签到失败'));
  142. }
  143. /**
  144. * 获取一条用户地址
  145. * @param string $addressId 地址id
  146. * @return \think\response\Json
  147. */
  148. public function get_user_address($addressId = ''){
  149. $addressInfo = [];
  150. if($addressId && is_numeric($addressId) && UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']])){
  151. $addressInfo = UserAddress::find($addressId);
  152. }
  153. return JsonService::successful($addressInfo);
  154. }
  155. /**
  156. * 获取默认地址
  157. * @return \think\response\Json
  158. */
  159. public function user_default_address()
  160. {
  161. $defaultAddress = UserAddress::getUserDefaultAddress($this->userInfo['uid'],'id,real_name,phone,province,city,district,detail,is_default');
  162. if($defaultAddress) return JsonService::successful('ok',$defaultAddress);
  163. else return JsonService::successful('empty',[]);
  164. }
  165. /**
  166. * 删除地址
  167. * @param string $addressId 地址id
  168. * @return \think\response\Json
  169. */
  170. public function remove_user_address($addressId = '')
  171. {
  172. if(!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!');
  173. if(!UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']]))
  174. return JsonService::fail('地址不存在!');
  175. if(UserAddress::edit(['is_del'=>'1'],$addressId,'id'))
  176. return JsonService::successful();
  177. else
  178. return JsonService::fail('删除地址失败!');
  179. }
  180. /**
  181. * 个人中心 获取订单列表
  182. * @param string $type
  183. * @param int $first
  184. * @param int $limit
  185. * @param string $search
  186. * @return \think\response\Json
  187. */
  188. public function get_user_order_list()
  189. {
  190. list($type,$page,$limit,$search)=UtilService::getMore([
  191. ['type',''],
  192. ['page',''],
  193. ['limit',''],
  194. ['search',''],
  195. ],$this->request,true);
  196. return JsonService::successful(StoreOrder::getUserOrderSearchList($this->uid,$type,$page,$limit,$search));
  197. }
  198. /**
  199. * 个人中心 订单详情页
  200. * @param string $order_id
  201. * @return \think\response\Json
  202. */
  203. public function get_order($uni = ''){
  204. if($uni == '') return JsonService::fail('参数错误');
  205. $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
  206. $order = $order->toArray();
  207. $order['add_time_y'] = date('Y-m-d',$order['add_time']);
  208. $order['add_time_h'] = date('H:i:s',$order['add_time']);
  209. if(!$order) return JsonService::fail('订单不存在');
  210. return JsonService::successful(StoreOrder::tidyOrder($order,true,true));
  211. }
  212. /**
  213. * 个人中心 删除订单
  214. * @param string $uni
  215. * @return \think\response\Json
  216. */
  217. public function user_remove_order($uni = '')
  218. {
  219. if(!$uni) return JsonService::fail('参数错误!');
  220. $res = StoreOrder::removeOrder($uni,$this->userInfo['uid']);
  221. if($res)
  222. return JsonService::successful();
  223. else
  224. return JsonService::fail(StoreOrder::getErrorInfo());
  225. }
  226. /**
  227. * 获取用户手机号码
  228. * @param Request $request
  229. * @return \think\response\Json
  230. */
  231. public function bind_mobile(Request $request){
  232. list($iv,$cache_key,$encryptedData) = UtilService::postMore([
  233. ['iv',''],
  234. ['cache_key',''],
  235. ['encryptedData',''],
  236. ],$request,true);
  237. $iv = urldecode(urlencode($iv));
  238. try{
  239. if(!Cache::has('eb_api_code_'.$cache_key)) return JsonService::fail('获取手机号失败');
  240. $session_key=Cache::get('eb_api_code_'.$cache_key);
  241. $userInfo = \app\core\util\MiniProgramService::encryptor($session_key,$iv,$encryptedData);
  242. if(!empty($userInfo['purePhoneNumber'])){
  243. if(User::edit(['phone'=>$userInfo['purePhoneNumber']],$this->userInfo['uid']))
  244. return JsonService::successful('绑定成功',['phone'=>$userInfo['purePhoneNumber']]);
  245. else
  246. return JsonService::fail('绑定失败');
  247. }else
  248. return JsonService::fail('获取手机号失败');
  249. }catch (\Exception $e){
  250. return JsonService::fail('error',$e->getMessage());
  251. }
  252. }
  253. /**
  254. * 个人中心 用户确认收货
  255. * @param string $uni
  256. * @return \think\response\Json
  257. */
  258. public function user_take_order($uni = '')
  259. {
  260. if(!$uni) return JsonService::fail('参数错误!');
  261. $res = StoreOrder::takeOrder($uni,$this->userInfo['uid']);
  262. if($res)
  263. return JsonService::successful();
  264. else
  265. return JsonService::fail(StoreOrder::getErrorInfo());
  266. }
  267. /**
  268. * 个人中心 充值
  269. * @param int $price
  270. * @return \think\response\Json
  271. */
  272. public function user_wechat_recharge($price = 0)
  273. {
  274. if(!$price || $price <=0) return JsonService::fail('参数错误');
  275. $storeMinRecharge = SystemConfigService::get('store_user_min_recharge');
  276. if($price < $storeMinRecharge) return JsonService::fail('充值金额不能低于'.$storeMinRecharge);
  277. $rechargeOrder = UserRecharge::addRecharge($this->userInfo['uid'],$price);
  278. if(!$rechargeOrder) return JsonService::fail('充值订单生成失败!');
  279. try{
  280. return JsonService::successful(UserRecharge::jsPay($rechargeOrder));
  281. }catch (\Exception $e){
  282. return JsonService::fail($e->getMessage());
  283. }
  284. }
  285. /**
  286. * 个人中心 余额使用记录
  287. * @param int $first
  288. * @param int $limit
  289. * @return \think\response\Json
  290. */
  291. public function user_balance_list($first = 0,$limit = 8)
  292. {
  293. return JsonService::successful(UserBill::userBillList($this->uid,$first,$limit,'now_money'));
  294. }
  295. /**
  296. * 个人中心 积分使用记录
  297. * @param int $first
  298. * @param int $limit
  299. * @return \think\response\Json
  300. */
  301. public function user_integral_list($page = 0,$limit = 8)
  302. {
  303. return JsonService::successful(UserBill::userBillList($this->uid,$page,$limit));
  304. }
  305. /**
  306. * 个人中心 获取一级推荐人
  307. * @param int $first
  308. * @param int $limit
  309. * @return \think\response\Json
  310. */
  311. public function get_spread_list($first = 0,$limit = 20)
  312. {
  313. return JsonService::successful(User::getSpreadList($this->uid,$first,$limit));
  314. }
  315. /**
  316. * 个人中心 获取二级推荐人
  317. * @param int $first
  318. * @param int $limit
  319. * @return \think\response\Json
  320. */
  321. public function get_spread_list_two($two_uid=0,$first = 0,$limit = 20)
  322. {
  323. return JsonService::successful(User::getSpreadList($two_uid,$first,$limit));
  324. }
  325. /**
  326. * 获取用户所有地址
  327. * @return \think\response\Json
  328. */
  329. public function user_address_list($page=1,$limit=8)
  330. {
  331. $list = UserAddress::getUserValidAddressList($this->userInfo['uid'],$page,$limit,'id,real_name,phone,province,city,district,detail,is_default');
  332. return JsonService::successful($list);
  333. }
  334. /**
  335. * 修改用户通知为已查看
  336. * @param $nid
  337. * @return \think\response\Json
  338. */
  339. public function see_notice($nid)
  340. {
  341. UserNotice::seeNotice($this->userInfo['uid'],$nid);
  342. return JsonService::successful();
  343. }
  344. /*
  345. * 用户提现申请
  346. * @param array
  347. * @return \think\response\Json
  348. * */
  349. public function user_extract()
  350. {
  351. $data=UtilService::postMore([
  352. ['alipay_code',''],
  353. ['extract_type',''],
  354. ['money',0],
  355. ['name',''],
  356. ['bankname',''],
  357. ['cardnum',''],
  358. ],$this->request);
  359. if(UserExtract::userExtract($this->userInfo,$data))
  360. return JsonService::successful('申请提现成功!');
  361. else
  362. return JsonService::fail(UserExtract::getErrorInfo('提现失败'));
  363. }
  364. /**
  365. * 用户下级的订单
  366. * @param int $first
  367. * @param int $limit
  368. * @return json
  369. */
  370. public function subordinateOrderlist($first = 0, $limit = 8)
  371. {
  372. list($xUid,$status)=UtilService::postMore([
  373. ['uid',''],
  374. ['status',''],
  375. ],$this->request,true);
  376. switch ($status){
  377. case 0:
  378. $type='';
  379. break;
  380. case 1:
  381. $type=4;
  382. break;
  383. case 2:
  384. $type=3;
  385. break;
  386. default:
  387. return JsonService::fail();
  388. }
  389. return JsonService::successful(StoreOrder::getSubordinateOrderlist($xUid,$this->uid,$type,$first,$limit));
  390. }
  391. /**
  392. * 个人中心 用户下级的订单
  393. * @param int $first
  394. * @param int $limit
  395. * @return json
  396. */
  397. public function subordinateOrderlistmoney()
  398. {
  399. $request = Request::instance();
  400. $lists=$request->param();
  401. $status = $lists['status'];
  402. $type = '';
  403. if($status == 1) $type = 4;
  404. elseif($status == 2) $type = 3;
  405. $arr = User::where('spread_uid',$this->userInfo['uid'])->column('uid');
  406. $list = StoreOrder::getUserOrderCount(implode(',',$arr),$type);
  407. $price = [];
  408. // if(!empty($list)) foreach ($list as $k=>$v) $price[]=$v['pay_price'];
  409. if(!empty($list)) foreach ($list as $k=>$v) $price[]=$v;
  410. $cont = count($list);
  411. $sum = array_sum($price);
  412. return JsonService::successful(['cont'=>$cont,'sum'=>$sum]);
  413. }
  414. /*
  415. * 用户提现记录列表
  416. * @param int $first 截取行数
  417. * @param int $limit 展示条数
  418. * @return json
  419. */
  420. public function extract($first = 0,$limit = 8)
  421. {
  422. return JsonService::successful(UserExtract::extractList($this->uid,$first,$limit));
  423. }
  424. /**
  425. * 个人中心 订单 评价订单
  426. * @param string $unique
  427. * @return \think\response\Json
  428. */
  429. public function user_comment_product($unique = '')
  430. {
  431. if(!$unique) return JsonService::fail('参数错误!');
  432. $cartInfo = StoreOrderCartInfo::where('unique',$unique)->find();
  433. $uid = $this->userInfo['uid'];
  434. if(!$cartInfo || $uid != $cartInfo['cart_info']['uid']) return JsonService::fail('评价产品不存在!');
  435. if(StoreProductReply::be(['oid'=>$cartInfo['oid'],'unique'=>$unique]))
  436. return JsonService::fail('该产品已评价!');
  437. $group = UtilService::postMore([
  438. ['comment',''],['pics',[]],['product_score',5],['service_score',5]
  439. ],Request::instance());
  440. $group['comment'] = htmlspecialchars(trim($group['comment']));
  441. if($group['product_score'] < 1) return JsonService::fail('请为产品评分');
  442. else if($group['service_score'] < 1) return JsonService::fail('请为商家服务评分');
  443. if($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
  444. else if($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
  445. else if($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
  446. else $productId = $cartInfo['product_id'];
  447. $group = array_merge($group,[
  448. 'uid'=>$uid,
  449. 'oid'=>$cartInfo['oid'],
  450. 'unique'=>$unique,
  451. 'product_id'=>$productId,
  452. 'reply_type'=>'product'
  453. ]);
  454. StoreProductReply::beginTrans();
  455. $res = StoreProductReply::reply($group,'product');
  456. if(!$res) {
  457. StoreProductReply::rollbackTrans();
  458. return JsonService::fail('评价失败!');
  459. }
  460. try{
  461. // HookService::listen('store_product_order_reply',$group,$cartInfo,false,StoreProductBehavior::class);
  462. StoreOrder::checkOrderOver($cartInfo['oid']);
  463. }catch (\Exception $e){
  464. StoreProductReply::rollbackTrans();
  465. return JsonService::fail($e->getMessage());
  466. }
  467. StoreProductReply::commitTrans();
  468. return JsonService::successful();
  469. }
  470. /*
  471. * 个人中心 查物流
  472. * @param int $uid 用户id
  473. * @param string $uni 订单id或者订单唯一键
  474. * @return json
  475. */
  476. public function express($uni = '')
  477. {
  478. if(!$uni || !($order = StoreOrder::getUserOrderDetail($this->uid,$uni))) return JsonService::fail('查询订单不存在!');
  479. if($order['delivery_type'] != 'express' || !$order['delivery_id']) return JsonService::fail('该订单不存在快递单号!');
  480. $cacheName = $uni.$order['delivery_id'];
  481. CacheService::rm($cacheName);
  482. $result = CacheService::get($cacheName,null);
  483. if($result === NULL){
  484. $result = Express::query($order['delivery_id']);
  485. if(is_array($result) &&
  486. isset($result['result']) &&
  487. isset($result['result']['deliverystatus']) &&
  488. $result['result']['deliverystatus'] >= 3)
  489. $cacheTime = 0;
  490. else
  491. $cacheTime = 1800;
  492. CacheService::set($cacheName,$result,$cacheTime);
  493. }
  494. return JsonService::successful([ 'order'=>StoreOrder::tidyOrder($order,true), 'express'=>$result ? $result : []]);
  495. }
  496. /**
  497. * 修改收货地址
  498. * @return \think\response\Json
  499. */
  500. public function edit_user_address()
  501. {
  502. $request = Request::instance();
  503. if(!$request->isPost()) return JsonService::fail('参数错误!');
  504. $addressInfo = UtilService::postMore([
  505. ['address',[]],
  506. ['is_default',false],
  507. ['real_name',''],
  508. ['post_code',''],
  509. ['phone',''],
  510. ['detail',''],
  511. ['id',0]
  512. ],$request);
  513. $addressInfo['province'] = $addressInfo['address']['province'];
  514. $addressInfo['city'] = $addressInfo['address']['city'];
  515. $addressInfo['district'] = $addressInfo['address']['district'];
  516. $addressInfo['is_default'] = $addressInfo['is_default'] == true ? 1 : 0;
  517. $addressInfo['uid'] = $this->userInfo['uid'];
  518. unset($addressInfo['address']);
  519. if($addressInfo['id'] && UserAddress::be(['id'=>$addressInfo['id'],'uid'=>$this->userInfo['uid'],'is_del'=>0])){
  520. $id = $addressInfo['id'];
  521. unset($addressInfo['id']);
  522. if(UserAddress::edit($addressInfo,$id,'id')){
  523. if($addressInfo['is_default'])
  524. UserAddress::setDefaultAddress($id,$this->userInfo['uid']);
  525. return JsonService::successful();
  526. }else
  527. return JsonService::fail('编辑收货地址失败!');
  528. }else{
  529. if($address = UserAddress::set($addressInfo)){
  530. if($addressInfo['is_default'])
  531. UserAddress::setDefaultAddress($address->id,$this->userInfo['uid']);
  532. return JsonService::successful(['id'=>$address->id]);
  533. }else
  534. return JsonService::fail('添加收货地址失败!');
  535. }
  536. }
  537. /**
  538. * 用户通知
  539. * @param int $page
  540. * @param int $limit
  541. * @return \think\response\Json
  542. */
  543. public function get_notice_list($page = 0, $limit = 8)
  544. {
  545. $list = UserNotice::getNoticeList($this->userInfo['uid'],$page,$limit);
  546. return JsonService::successful($list);
  547. }
  548. /*
  549. * 昨日推广佣金
  550. * @return json
  551. */
  552. public function yesterday_commission()
  553. {
  554. return JsonService::successful(UserBill::yesterdayCommissionSum($this->uid));
  555. }
  556. /*
  557. * 累计已提金额
  558. * @return json
  559. */
  560. public function extractsum()
  561. {
  562. return JsonService::successful(UserExtract::extractSum($this->uid));
  563. }
  564. /**
  565. * 绑定推荐人
  566. * @param Request $request
  567. * @return \think\response\Json
  568. */
  569. public function spread_uid(Request $request){
  570. $data = UtilService::postMore(['spread_uid',0],$request);
  571. if($data['spread_uid']){
  572. if(!$this->userInfo['spread_uid']){
  573. $res = User::edit(['spread_uid'=>$data['spread_uid']],$this->userInfo['uid']);
  574. if($res) return JsonService::successful('绑定成功');
  575. else return JsonService::successful('绑定失败');
  576. }else return JsonService::fail('已存在被推荐人');
  577. }else return JsonService::fail('没有推荐人');
  578. }
  579. /**
  580. * 设置为默认地址
  581. * @param string $addressId
  582. * @return \think\response\Json
  583. */
  584. public function set_user_default_address($addressId = '')
  585. {
  586. if(!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!');
  587. if(!UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']]))
  588. return JsonService::fail('地址不存在!');
  589. $res = UserAddress::setDefaultAddress($addressId,$this->userInfo['uid']);
  590. if(!$res)
  591. return JsonService::fail('地址不存在!');
  592. else
  593. return JsonService::successful();
  594. }
  595. /**
  596. * 获取分销二维码
  597. * @return \think\response\Json
  598. */
  599. public function get_code(){
  600. header('content-type:image/jpg');
  601. if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
  602. $path = makePathToUrl('routine/code');
  603. if($path == '')
  604. return JsonService::fail('生成上传目录失败,请检查权限!');
  605. $picname = $path.'/'.$this->userInfo['uid'].'.jpg';
  606. $domain = SystemConfigService::get('site_url').'/';
  607. $domainTop = substr($domain,0,5);
  608. if($domainTop != 'https') $domain = 'https:'.substr($domain,5,strlen($domain));
  609. if(file_exists($picname)) return JsonService::successful($domain.$picname);
  610. else{
  611. $res = RoutineCode::getCode($this->userInfo['uid'],$picname);
  612. if($res) file_put_contents($picname,$res);
  613. else return JsonService::fail('二维码生成失败');
  614. }
  615. return JsonService::successful($domain.$picname);
  616. }
  617. /*
  618. * 修改用户信息
  619. * */
  620. public function edit_user($formid=''){
  621. list($avatar,$nickname)=UtilService::postMore([
  622. ['avatar',''],
  623. ['nickname',''],
  624. ],$this->request,true);
  625. RoutineFormId::SetFormId($formid,$this->uid);
  626. if(User::editUser($avatar,$nickname,$this->uid))
  627. return JsonService::successful('修改成功');
  628. else
  629. return JsonService::fail('');
  630. }
  631. /*
  632. * 查找用户消费充值记录
  633. *
  634. * */
  635. public function get_user_bill_list($page=1,$limit=8,$type=0)
  636. {
  637. return JsonService::successful(UserBill::getUserBillList($this->uid,$page,$limit,$type));
  638. }
  639. /*
  640. * 获取活动是否存在
  641. * */
  642. public function get_activity()
  643. {
  644. $data['is_bargin']=StoreBargain::validBargain() ? true : false;
  645. $data['is_pink']=StoreCombination::getPinkIsOpen() ? true : false;
  646. $data['is_seckill']=StoreSeckill::getSeckillCount() ? true : false;
  647. return JsonService::successful($data);
  648. }
  649. /**
  650. * TODO 获取记录总和
  651. * @param int $type
  652. */
  653. public function get_record_list_count($type = 3)
  654. {
  655. $count = 0;
  656. if($type == 3) $count = UserBill::getRecordCount($this->uid, 'now_money', 'brokerage');
  657. else if($type == 4) $count = UserExtract::userExtractTotalPrice($this->uid);//累计提现
  658. $count = $count ? $count : 0;
  659. JsonService::successful('',$count);
  660. }
  661. /**
  662. * TODO 获取订单返佣记录
  663. * @param int $first
  664. * @param int $limit
  665. * @param string $category
  666. * @param string $type
  667. */
  668. public function get_record_order_list($page = 0,$limit = 8,$category = 'now_money', $type = 'brokerage'){
  669. $data['list'] = [];
  670. $data['count'] = 0;
  671. $data['list'] = UserBill::getRecordList($this->uid,$page,$limit,$category,$type);
  672. $count = UserBill::getRecordOrderCount($this->uid, $category, $type);
  673. $data['count'] = $count ? $count : 0;
  674. if(!count($data['list'])) return JsonService::successful([]);
  675. foreach ($data['list'] as $key=>&$value){
  676. $value['child'] = UserBill::getRecordOrderListDraw($this->uid, $value['time'],$category, $type);
  677. $value['count'] = count($value['child']);
  678. }
  679. return JsonService::successful($data);
  680. }
  681. /**
  682. * TODO 获取推广人列表
  683. * @param int $first
  684. * @param int $limit
  685. * @param int $type
  686. * @param int $keyword
  687. * @param string $order
  688. */
  689. public function user_spread_new_list($page = 0,$limit = 8,$grade = 0,$keyword = 0,$sort = ''){
  690. if(!$keyword) $keyword = '';
  691. $data['list'] = User::getUserSpreadGrade($this->userInfo['uid'],$grade,$sort,$keyword,$page,$limit);
  692. $data['total'] = User::getSpreadCount($this->uid);
  693. $data['totalLevel'] = User::getSpreadLevelCount($this->uid);
  694. return JsonService::successful($data);
  695. }
  696. /**
  697. * 分销二维码海报生成
  698. */
  699. public function user_spread_banner_list(){
  700. header('content-type:image/jpg');
  701. try{
  702. $routineSpreadBanner = GroupDataService::getData('routine_spread_banner');
  703. if(!count($routineSpreadBanner)) return JsonService::fail('暂无海报');
  704. $pathCode = makePathToUrl('routine/spread/code',3);
  705. if($pathCode == '') return JsonService::fail('生成上传目录失败,请检查权限!');
  706. $picName = $pathCode.DS.$this->userInfo['uid'].'.jpg';
  707. $picName = trim(str_replace(DS, '/',$picName,$loop));
  708. $res = RoutineCode::getShareCode($this->uid, 'spread', '', $picName);
  709. if($res) file_put_contents($picName,$res);
  710. else return JsonService::fail('二维码生成失败');
  711. $res = true;
  712. $url = SystemConfigService::get('site_url').'/';
  713. $domainTop = substr($url,0,5);
  714. if($domainTop != 'https') $url = 'https:'.substr($url,5,strlen($url));
  715. $pathCode = makePathToUrl('routine/spread/poster',3);
  716. $filelink=[
  717. 'Bold'=>'public/static/font/SourceHanSansCN-Bold.otf',
  718. 'Normal'=>'public/static/font/SourceHanSansCN-Normal.otf',
  719. ];
  720. if(!file_exists($filelink['Bold'])) return JsonService::fail('缺少字体文件Bold');
  721. if(!file_exists($filelink['Normal'])) return JsonService::fail('缺少字体文件Normal');
  722. foreach ($routineSpreadBanner as $key=>&$item){
  723. $config = array(
  724. 'image'=>array(
  725. array(
  726. 'url'=>ROOT_PATH.$picName, //二维码资源
  727. 'stream'=>0,
  728. 'left'=>114,
  729. 'top'=>790,
  730. 'right'=>0,
  731. 'bottom'=>0,
  732. 'width'=>120,
  733. 'height'=>120,
  734. 'opacity'=>100
  735. )
  736. ),
  737. 'text'=>array(
  738. array(
  739. 'text'=>$this->userInfo['nickname'],
  740. 'left'=>250,
  741. 'top'=>840,
  742. 'fontPath'=>ROOT_PATH.$filelink['Bold'], //字体文件
  743. 'fontSize'=>16, //字号
  744. 'fontColor'=>'40,40,40', //字体颜色
  745. 'angle'=>0,
  746. ),
  747. array(
  748. 'text'=>'邀请您加入'.SystemConfigService::get('site_name'),
  749. 'left'=>250,
  750. 'top'=>880,
  751. 'fontPath'=>ROOT_PATH.$filelink['Normal'], //字体文件
  752. 'fontSize'=>16, //字号
  753. 'fontColor'=>'40,40,40', //字体颜色
  754. 'angle'=>0,
  755. )
  756. ),
  757. 'background'=>$item['pic']
  758. );
  759. $filename = ROOT_PATH.$pathCode.'/'.$item['id'].'_'.$this->uid.'.png';
  760. $res = $res && UtilService::setSharePoster($config,$filename);
  761. if($res) $item['poster'] = $url.$pathCode.'/'.$item['id'].'_'.$this->uid.'.png';
  762. }
  763. if($res) return JsonService::successful($routineSpreadBanner);
  764. else return JsonService::fail('生成图片失败');
  765. }catch (\Exception $e){
  766. return JsonService::fail('生成图片时,系统错误',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
  767. }
  768. }
  769. }