UserApi.php 32 KB

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