User.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 个人信息
  7. */
  8. namespace app\smartbc\controller\api\v1;
  9. use app\smartbc\controller\api\Base;
  10. use app\smartbc\model\SmartbcBill;
  11. use app\smartbc\model\SmartbcCouponUser;
  12. use app\smartbc\model\SmartbcConfig;
  13. use think\helper\Time;
  14. class User extends Base{
  15. /**
  16. * 个人信息
  17. * @return void
  18. */
  19. public function initialize() {
  20. parent::initialize();
  21. $this->isUserAuth();
  22. }
  23. /**
  24. * 账单
  25. */
  26. public function bill(){
  27. $param['today'] = $this->request->param('today/d',0);
  28. $param['page'] = $this->request->param('page/d',1);
  29. $param['sign'] = $this->request->param('sign');
  30. $rel = $this->apiSign($param);
  31. if($rel['code'] != 200){
  32. return enjson(500,'签名验证失败');
  33. }
  34. $condition[] = ['uid','=',$this->user->id];
  35. $times = Time::today();
  36. if($param['today']){
  37. $condition[] = ['update_time','<',$times[1]]; //历史
  38. }else{
  39. $condition[] = ['update_time','>',$times[0]]; //今天
  40. }
  41. $info = SmartbcBill::withAttr('update_time', function ($value, $data) {
  42. return date('Y-m-d H:i',$value);
  43. })->with(['user'=> function($query) {
  44. $query->field('id,face,nickname');
  45. }])->where($condition)->order('id desc')->page($param['page'],10)->select();
  46. if($info->isEmpty()){
  47. return enjson(204);
  48. }
  49. return enjson(200,$info);
  50. }
  51. }