作者 SHW\戥岁。。

分类购物车数量

@@ -31,22 +31,24 @@ class Cart extends Api @@ -31,22 +31,24 @@ class Cart extends Api
31 */ 31 */
32 public function addCart() 32 public function addCart()
33 { 33 {
34 - $sku_id = $this->request->post('sku_id'); 34 + $sku_id = $this->request->post('sku_id');
35 $goods_id = $this->request->post('goods_id'); 35 $goods_id = $this->request->post('goods_id');
36 - $number = $this->request->post('number'); 36 + $number = $this->request->post('number');
37 37
38 if (!is_numeric($sku_id) || !is_numeric($goods_id) || !is_numeric($number)) $this->error('参数不合法'); 38 if (!is_numeric($sku_id) || !is_numeric($goods_id) || !is_numeric($number)) $this->error('参数不合法');
  39 + $category_id = (new \app\api\model\Goods())->where('id', $goods_id)->value('category_id');
39 40
40 - $data = [  
41 - 'user_id' => $this->auth->id,  
42 - 'sku_id' => $sku_id,  
43 - 'goods_id' => $goods_id, 41 + $data = [
  42 + 'user_id' => $this->auth->id,
  43 + 'category_id' => $category_id,
  44 + 'sku_id' => $sku_id,
  45 + 'goods_id' => $goods_id,
44 ]; 46 ];
45 $model = new \app\api\model\Cart(); 47 $model = new \app\api\model\Cart();
46 - $cart = $model->where($data)->find();  
47 - if ($cart){  
48 - $cart->setInc('number',$number);  
49 - }else{ 48 + $cart = $model->where($data)->find();
  49 + if ($cart) {
  50 + $cart->setInc('number', $number);
  51 + } else {
50 $data['number'] = $number; 52 $data['number'] = $number;
51 $model->isUpdate(false)->save($data); 53 $model->isUpdate(false)->save($data);
52 } 54 }
@@ -68,12 +70,12 @@ class Cart extends Api @@ -68,12 +70,12 @@ class Cart extends Api
68 { 70 {
69 $ids = $this->request->post('cart_ids'); 71 $ids = $this->request->post('cart_ids');
70 if (!$ids) $this->error('参数不可为空'); 72 if (!$ids) $this->error('参数不可为空');
71 - $ids = explode(',',$ids);  
72 - foreach ($ids as $key => $value){ 73 + $ids = explode(',', $ids);
  74 + foreach ($ids as $key => $value) {
73 if (!is_numeric($value)) $this->error('参数不合法'); 75 if (!is_numeric($value)) $this->error('参数不合法');
74 } 76 }
75 $model = new \app\api\model\Cart(); 77 $model = new \app\api\model\Cart();
76 - $model->whereIn('id',$ids)->delete(); 78 + $model->whereIn('id', $ids)->delete();
77 $this->success('SUCCESS'); 79 $this->success('SUCCESS');
78 } 80 }
79 81
@@ -90,15 +92,15 @@ class Cart extends Api @@ -90,15 +92,15 @@ class Cart extends Api
90 */ 92 */
91 public function addCartNumber() 93 public function addCartNumber()
92 { 94 {
93 - $id = $this->request->post('id'); 95 + $id = $this->request->post('id');
94 $number = $this->request->post('number'); 96 $number = $this->request->post('number');
95 97
96 - if (!is_numeric($id) || !is_numeric($number)) $this->error('参数不合法'); 98 + if (!is_numeric($id) || !is_numeric($number)) $this->error('参数不合法');
97 99
98 $model = new \app\api\model\Cart(); 100 $model = new \app\api\model\Cart();
99 - $order = $model->with('sku')->where('id',$id)->find();  
100 - if ($number+$order['number'] > $order['sku']['stock_num']) $this->error('已达到最大库存,请勿重复提交');  
101 - $model->where('id',$id)->setInc('number',$number); 101 + $order = $model->with('sku')->where('id', $id)->find();
  102 + if ($number + $order['number'] > $order['sku']['stock_num']) $this->error('已达到最大库存,请勿重复提交');
  103 + $model->where('id', $id)->setInc('number', $number);
102 $this->success('SUCCESS'); 104 $this->success('SUCCESS');
103 } 105 }
104 106
@@ -115,16 +117,16 @@ class Cart extends Api @@ -115,16 +117,16 @@ class Cart extends Api
115 */ 117 */
116 public function subCartNumber() 118 public function subCartNumber()
117 { 119 {
118 - $id = $this->request->post('id'); 120 + $id = $this->request->post('id');
119 $number = $this->request->post('number'); 121 $number = $this->request->post('number');
120 122
121 - if (!is_numeric($id) || !is_numeric($number)) $this->error('参数不合法'); 123 + if (!is_numeric($id) || !is_numeric($number)) $this->error('参数不合法');
122 124
123 $model = new \app\api\model\Cart(); 125 $model = new \app\api\model\Cart();
124 - if ($model->where('id',$id)->value('number') ==1){ 126 + if ($model->where('id', $id)->value('number') == 1) {
125 $this->error('购物车数量不可再减少'); 127 $this->error('购物车数量不可再减少');
126 - }else{  
127 - $model->where('id',$id)->setDec('number',$number); 128 + } else {
  129 + $model->where('id', $id)->setDec('number', $number);
128 } 130 }
129 $this->success('SUCCESS'); 131 $this->success('SUCCESS');
130 } 132 }
@@ -137,54 +139,54 @@ class Cart extends Api @@ -137,54 +139,54 @@ class Cart extends Api
137 'code':'1', 139 'code':'1',
138 'msg':'SUCCESS' 140 'msg':'SUCCESS'
139 'data' 141 'data'
140 - {  
141 - "id": 1, 购车id  
142 - "user_id": 0,  
143 - "goods_id": 21, 商品id  
144 - "sku_id": 125, 规格id  
145 - "number": 10, 购买数量  
146 - "createtime": null,  
147 - "goods": {  
148 - "goods_id": 21,  
149 - "goods_name": "小米Mix3",  
150 - "image_text": "http://temporaryfood.qiniu.broing.cn123132", 封面图  
151 - "images_text": [  
152 - "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/ffc4440df18661948b9c2d4dd4ae419b.jpg",  
153 - "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/83bf8f141969a9e3e607a768407fc7e0.jpg",  
154 - "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/c5d85254fc17b1a1b0e2254470881e59.jpg"  
155 - ],  
156 - "down_image_text": "http://temporaryfood.qiniu.broing.cn/uploads/20220114/f8bb72e2ce3e70f0a9f54e6c0b4a6c14.png",  
157 - "four_image_text": []  
158 - },  
159 - "sku": {  
160 - "goods_spec_id": 125,  
161 - "goods_price": "100.00", 价格  
162 - "spec_sku_id": "40_54",  
163 - "sku_name": "黑色 1" 规格名  
164 - }  
165 - } 142 + {
  143 + "id": 1, 购车id
  144 + "user_id": 0,
  145 + "goods_id": 21, 商品id
  146 + "sku_id": 125, 规格id
  147 + "number": 10, 购买数量
  148 + "createtime": null,
  149 + "goods": {
  150 + "goods_id": 21,
  151 + "goods_name": "小米Mix3",
  152 + "image_text": "http://temporaryfood.qiniu.broing.cn123132", 封面图
  153 + "images_text": [
  154 + "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/ffc4440df18661948b9c2d4dd4ae419b.jpg",
  155 + "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/83bf8f141969a9e3e607a768407fc7e0.jpg",
  156 + "https://her-family.oss-cn-qingdao.aliyuncs.com/addons_store_uploads/20181105/c5d85254fc17b1a1b0e2254470881e59.jpg"
  157 + ],
  158 + "down_image_text": "http://temporaryfood.qiniu.broing.cn/uploads/20220114/f8bb72e2ce3e70f0a9f54e6c0b4a6c14.png",
  159 + "four_image_text": []
  160 + },
  161 + "sku": {
  162 + "goods_spec_id": 125,
  163 + "goods_price": "100.00", 价格
  164 + "spec_sku_id": "40_54",
  165 + "sku_name": "黑色 1" 规格名
  166 + }
  167 + }
166 }) 168 })
167 */ 169 */
168 public function cartList() 170 public function cartList()
169 { 171 {
170 $model = new \app\api\model\Cart(); 172 $model = new \app\api\model\Cart();
171 - $list = $model  
172 - ->with(['goods','sku'])  
173 - ->where('user_id',$this->auth->id) 173 + $list = $model
  174 + ->with(['goods', 'sku'])
  175 + ->where('user_id', $this->auth->id)
174 ->order('createtime desc') 176 ->order('createtime desc')
175 ->select(); 177 ->select();
176 - foreach ($list as $key => $value){  
177 - $value->getRelation('goods')->visible(['goods_name','goods_id']);  
178 - $value->getRelation('sku')->visible(['goods_spec_id','goods_price','spec_sku_id']); 178 + foreach ($list as $key => $value) {
  179 + $value->getRelation('goods')->visible(['goods_name', 'goods_id']);
  180 + $value->getRelation('sku')->visible(['goods_spec_id', 'goods_price', 'spec_sku_id']);
179 } 181 }
180 $list = collection($list)->toArray(); 182 $list = collection($list)->toArray();
181 - foreach ($list as $k => &$val){  
182 - $skuids = explode('_', $val['sku']['spec_sku_id']);  
183 - $sku = Db::name('litestore_spec_value')->where('id','in',$skuids)->column('spec_value');  
184 - $skuname = !empty($sku)?implode(' ',$sku):''; 183 + foreach ($list as $k => &$val) {
  184 + $skuids = explode('_', $val['sku']['spec_sku_id']);
  185 + $sku = Db::name('litestore_spec_value')->where('id', 'in', $skuids)->column('spec_value');
  186 + $skuname = !empty($sku) ? implode(' ', $sku) : '';
185 $val['sku']['sku_name'] = $skuname; 187 $val['sku']['sku_name'] = $skuname;
186 } 188 }
187 - $this->success('SUCCESS',$list); 189 + $this->success('SUCCESS', $list);
188 } 190 }
189 191
190 /** 192 /**
@@ -208,23 +210,23 @@ class Cart extends Api @@ -208,23 +210,23 @@ class Cart extends Api
208 $json = $this->request->param('data_json'); 210 $json = $this->request->param('data_json');
209 if (!$json) $this->error('data_json参数不能为空'); 211 if (!$json) $this->error('data_json参数不能为空');
210 // $json = '[{"goods_id":22,"goods_sku_id":106,"number":2},{"goods_id":23,"goods_sku_id":66,"number":2}]'; 212 // $json = '[{"goods_id":22,"goods_sku_id":106,"number":2},{"goods_id":23,"goods_sku_id":66,"number":2}]';
211 - $json = str_replace('"','"',$json);  
212 - $data = json_decode($json,true); 213 + $json = str_replace('"', '"', $json);
  214 + $data = json_decode($json, true);
213 $goodsmodel = new \app\api\model\Goods(); 215 $goodsmodel = new \app\api\model\Goods();
214 - $skumodel = new GoodsSpec();  
215 - $sum_price = 0; //总价格  
216 - foreach ($data as $key => $value){  
217 - if (!is_numeric($value['goods_id']) || !is_numeric($value['goods_sku_id']) || !is_numeric($value['number'])){ 216 + $skumodel = new GoodsSpec();
  217 + $sum_price = 0; //总价格
  218 + foreach ($data as $key => $value) {
  219 + if (!is_numeric($value['goods_id']) || !is_numeric($value['goods_sku_id']) || !is_numeric($value['number'])) {
218 $this->error('参数不合法'); 220 $this->error('参数不合法');
219 } 221 }
220 - $goods = $goodsmodel->where('goods_id',$value['goods_id'])->field('goods_id,goods_name,image,spec_type')->find(); 222 + $goods = $goodsmodel->where('goods_id', $value['goods_id'])->field('goods_id,goods_name,image,spec_type')->find();
221 if (!$goods) $this->error('商品不存在'); 223 if (!$goods) $this->error('商品不存在');
222 - $sku = $skumodel->where('goods_spec_id',$value['goods_sku_id']) 224 + $sku = $skumodel->where('goods_spec_id', $value['goods_sku_id'])
223 ->field('goods_spec_id,spec_sku_id,goods_price')->find(); 225 ->field('goods_spec_id,spec_sku_id,goods_price')->find();
224 if (!$sku) $this->error('商品规格不存在'); 226 if (!$sku) $this->error('商品规格不存在');
225 227
226 - $sum_price = bcadd($sum_price,bcmul($sku['goods_price'],$value['number'],2),2); 228 + $sum_price = bcadd($sum_price, bcmul($sku['goods_price'], $value['number'], 2), 2);
227 } 229 }
228 - $this->success('购物车页面价格',['price'=>$sum_price]); 230 + $this->success('购物车页面价格', ['price' => $sum_price]);
229 } 231 }
230 } 232 }
@@ -596,9 +596,8 @@ class Classification extends Api @@ -596,9 +596,8 @@ class Classification extends Api
596 */ 596 */
597 public function category_list() 597 public function category_list()
598 { 598 {
599 - $model = new Category();  
600 - $list = $model->field('id,name')->order('weigh desc')->select();  
601 - $cart_sum = 0; 599 + $model = new Category();
  600 + $list = $model->field('id,name')->order('weigh desc')->select();
602 foreach ($list as $key => &$value) { 601 foreach ($list as $key => &$value) {
603 $model = new Goods(); 602 $model = new Goods();
604 if ($this->auth->isLogin()) { 603 if ($this->auth->isLogin()) {
@@ -608,14 +607,18 @@ class Classification extends Api @@ -608,14 +607,18 @@ class Classification extends Api
608 ->where('goods_status', '10') 607 ->where('goods_status', '10')
609 ->field('goods_id') 608 ->field('goods_id')
610 ->select()->toArray(); 609 ->select()->toArray();
  610 + //如果该分类下没商品,则分类下购物车数量为零
  611 + if (empty($goods_list)) {
  612 + $value['category_cart_number'] = 0;
  613 + continue;
  614 + }
611 foreach ($goods_list as &$item) { 615 foreach ($goods_list as &$item) {
612 - $sum = Db::name('cart') 616 + $value['category_cart_number'] = Db::name('cart')
613 ->where('user_id', $this->auth->id) 617 ->where('user_id', $this->auth->id)
614 - ->where('goods_id', $item['goods_id']) 618 +// ->where('goods_id', $item['goods_id'])
  619 + ->where('category_id', $value['id'])
615 ->sum('number'); 620 ->sum('number');
616 - $cart_sum += $sum;  
617 } 621 }
618 - $value['category_cart_number'] = $cart_sum;  
619 } else { 622 } else {
620 $value['category_cart_number'] = 0; 623 $value['category_cart_number'] = 0;
621 } 624 }
@@ -18,7 +18,7 @@ use think\Validate; @@ -18,7 +18,7 @@ use think\Validate;
18 */ 18 */
19 class User extends Api 19 class User extends Api
20 { 20 {
21 - protected $noNeedLogin = ['third','joinUs','developLogin','notice']; 21 + protected $noNeedLogin = ['third', 'joinUs', 'developLogin', 'notice'];
22 protected $noNeedRight = '*'; 22 protected $noNeedRight = '*';
23 23
24 public function _initialize() 24 public function _initialize()
@@ -46,14 +46,14 @@ class User extends Api @@ -46,14 +46,14 @@ class User extends Api
46 */ 46 */
47 public function index() 47 public function index()
48 { 48 {
49 - $data = [];  
50 - $data['nickname'] = $this->auth->nickname;  
51 - $data['avatar'] = cdnurl($this->auth->avatar,true);  
52 - $data['mobile'] = $this->auth->mobile;  
53 - $data['pay'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('pay_status','10')->count();  
54 - $data['wait_send'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('freight_status','10')->count();  
55 - $data['wait_collect'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','10')->count();  
56 - $data['wait_comment'] = Db::name('litestore_order')->where('user_id',$this->auth->id)->where('receipt_status','20')->count(); 49 + $data = [];
  50 + $data['nickname'] = $this->auth->nickname;
  51 + $data['avatar'] = cdnurl($this->auth->avatar, true);
  52 + $data['mobile'] = $this->auth->mobile;
  53 + $data['pay'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('pay_status', '10')->count();
  54 + $data['wait_send'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('freight_status', '10')->count();
  55 + $data['wait_collect'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('receipt_status', '10')->count();
  56 + $data['wait_comment'] = Db::name('litestore_order')->where('user_id', $this->auth->id)->where('receipt_status', '20')->count();
57 $this->success('会员中心', ['welcome' => $data]); 57 $this->success('会员中心', ['welcome' => $data]);
58 } 58 }
59 59
@@ -61,16 +61,16 @@ class User extends Api @@ -61,16 +61,16 @@ class User extends Api
61 * 修改会员个人信息 61 * 修改会员个人信息
62 * 62 *
63 * @ApiMethod (POST) 63 * @ApiMethod (POST)
64 - * @param string $avatar 头像地址  
65 - * @param string $mobile 联系方式 64 + * @param string $avatar 头像地址
  65 + * @param string $mobile 联系方式
66 * @param string $nickname 昵称 66 * @param string $nickname 昵称
67 */ 67 */
68 public function profile() 68 public function profile()
69 { 69 {
70 - $user = $this->auth->getUser();  
71 - $mobile = $this->request->post('mobile'); 70 + $user = $this->auth->getUser();
  71 + $mobile = $this->request->post('mobile');
72 $nickname = $this->request->post('nickname'); 72 $nickname = $this->request->post('nickname');
73 - $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); 73 + $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
74 if ($mobile) { 74 if ($mobile) {
75 $user->mobile = $mobile; 75 $user->mobile = $mobile;
76 } 76 }
@@ -89,59 +89,59 @@ class User extends Api @@ -89,59 +89,59 @@ class User extends Api
89 * 第三方登录 89 * 第三方登录
90 * 90 *
91 * @ApiMethod (POST) 91 * @ApiMethod (POST)
92 - * @param string $code Code码 92 + * @param string $code Code码
93 * @param string $nickname 微信昵称 93 * @param string $nickname 微信昵称
94 - * @param string $avatar 微信头像  
95 - * @param string $invite_id 邀请人id。默认传0 94 + * @param string $avatar 微信头像
  95 + * @param string $invite_id 邀请人id。默认传0
96 */ 96 */
97 public function third() 97 public function third()
98 { 98 {
99 - $code = $this->request->post('code');  
100 - $nickname = $this->request->post('nickname');  
101 - $avatar = $this->request->post('avatar'); 99 + $code = $this->request->post('code');
  100 + $nickname = $this->request->post('nickname');
  101 + $avatar = $this->request->post('avatar');
102 $invite_id = $this->request->post('invite_id'); 102 $invite_id = $this->request->post('invite_id');
103 - if (!$code || !$nickname || !$avatar){ 103 + if (!$code || !$nickname || !$avatar) {
104 $this->error('后台所需参数缺失请完善参数'); 104 $this->error('后台所需参数缺失请完善参数');
105 } 105 }
106 - $param = [];  
107 - $param['js_code'] = $code; 106 + $param = [];
  107 + $param['js_code'] = $code;
108 $param['grant_type'] = 'authorization_code'; 108 $param['grant_type'] = 'authorization_code';
109 - $param['secret'] = Config::get('site.secret');  
110 - $param['appid'] = Config::get('site.appid');  
111 - $wxapi = Http::get('https://api.weixin.qq.com/sns/jscode2session',$param);//请求openid  
112 - $wxapi = json_decode($wxapi,true);  
113 - if (isset($wxapi['errcode'])){ 109 + $param['secret'] = Config::get('site.secret');
  110 + $param['appid'] = Config::get('site.appid');
  111 + $wxapi = Http::get('https://api.weixin.qq.com/sns/jscode2session', $param);//请求openid
  112 + $wxapi = json_decode($wxapi, true);
  113 + if (isset($wxapi['errcode'])) {
114 $this->error($wxapi['errmsg']); 114 $this->error($wxapi['errmsg']);
115 } 115 }
116 - $third = new \app\api\model\Third();  
117 - $userid = $third->where('openid',$wxapi['openid'])->value('user_id');  
118 - if ($userid){  
119 - $this->auth->direct($userid,$invite_id);  
120 - $third->isUpdate()->save(['session_key'=>$wxapi['session_key']],['user_id'=>$userid]);  
121 - $this->success('登录成功',['token'=>$this->auth->getToken(),'user_type'=>$this->auth->user_type]);  
122 - }else{  
123 - if ($invite_id > 0){  
124 - $userid = $this->auth->register($nickname,'','','',['avatar'=>$avatar,'invite_user_id'=>$invite_id,'invite_time'=>time()]);  
125 - }else{  
126 - $userid = $this->auth->register($nickname,'','','',['avatar'=>$avatar]); 116 + $third = new \app\api\model\Third();
  117 + $userid = $third->where('openid', $wxapi['openid'])->value('user_id');
  118 + if ($userid) {
  119 + $this->auth->direct($userid, $invite_id);
  120 + $third->isUpdate()->save(['session_key' => $wxapi['session_key']], ['user_id' => $userid]);
  121 + $this->success('登录成功', ['token' => $this->auth->getToken(), 'user_type' => $this->auth->user_type]);
  122 + } else {
  123 + if ($invite_id > 0) {
  124 + $userid = $this->auth->register($nickname, '', '', '', ['avatar' => $avatar, 'invite_user_id' => $invite_id, 'invite_time' => time()]);
  125 + } else {
  126 + $userid = $this->auth->register($nickname, '', '', '', ['avatar' => $avatar]);
127 } 127 }
128 - if ($userid){  
129 - $third->isUpdate(false)->save(['openid'=>$wxapi['openid'],'user_id'=>$userid,'session_key'=>$wxapi['session_key']]); 128 + if ($userid) {
  129 + $third->isUpdate(false)->save(['openid' => $wxapi['openid'], 'user_id' => $userid, 'session_key' => $wxapi['session_key']]);
130 // 注册送优惠券 130 // 注册送优惠券
131 - $coupon = Db::name('coupon')->where('id',3)->find();  
132 - $time = time();  
133 - if($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']){ 131 + $coupon = Db::name('coupon')->where('id', 3)->find();
  132 + $time = time();
  133 + if ($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']) {
134 UserCoupon::create([ 134 UserCoupon::create([
135 - 'user_id' => $userid,  
136 - 'coupon_id' => $coupon['id'],  
137 - 'name' => $coupon['name'],  
138 - 'price' => $coupon['price'], 135 + 'user_id' => $userid,
  136 + 'coupon_id' => $coupon['id'],
  137 + 'name' => $coupon['name'],
  138 + 'price' => $coupon['price'],
139 'full_price' => $coupon['full_price'], 139 'full_price' => $coupon['full_price'],
140 - 'endtime' => $time+$coupon['days']*86400 140 + 'endtime' => $time + $coupon['days'] * 86400,
141 ]); 141 ]);
142 } 142 }
143 - $this->success('登录成功',['token'=>$this->auth->getToken(),'user_type'=>$this->auth->user_type]);  
144 - }else{ 143 + $this->success('登录成功', ['token' => $this->auth->getToken(), 'user_type' => $this->auth->user_type]);
  144 + } else {
145 $this->error('注册失败'); 145 $this->error('注册失败');
146 } 146 }
147 } 147 }
@@ -154,30 +154,30 @@ class User extends Api @@ -154,30 +154,30 @@ class User extends Api
154 * @ApiParams (name="iv", type="string", required=true, description="小程序iv") 154 * @ApiParams (name="iv", type="string", required=true, description="小程序iv")
155 * @ApiParams (name="encryptedData", type="string", required=true, description="小程序encryptedData") 155 * @ApiParams (name="encryptedData", type="string", required=true, description="小程序encryptedData")
156 * @ApiReturn ({ 156 * @ApiReturn ({
157 - 'code':'1',  
158 - 'msg':'返回成功',  
159 - "data": {  
160 - "mobile": "13580006666", //没有区号的手机号  
161 - } 157 + 'code':'1',
  158 + 'msg':'返回成功',
  159 + "data": {
  160 + "mobile": "13580006666", //没有区号的手机号
  161 + }
162 }) 162 })
163 */ 163 */
164 public function getPhoneNumber() 164 public function getPhoneNumber()
165 { 165 {
166 - $param = $this->request->param(); 166 + $param = $this->request->param();
167 $validate = new \think\Validate([ 167 $validate = new \think\Validate([
168 - 'iv' => 'require', 168 + 'iv' => 'require',
169 'encryptedData' => 'require', 169 'encryptedData' => 'require',
170 ]); 170 ]);
171 $validate->message([ 171 $validate->message([
172 - 'iv.require' => 'iv参数错误!', 172 + 'iv.require' => 'iv参数错误!',
173 'encryptedData.require' => 'encryptData参数错误!', 173 'encryptedData.require' => 'encryptData参数错误!',
174 ]); 174 ]);
175 if (!$validate->check($param)) { 175 if (!$validate->check($param)) {
176 $this->error($validate->getError()); 176 $this->error($validate->getError());
177 } 177 }
178 // 获取session_key 178 // 获取session_key
179 - $user = $this->auth->getUser();  
180 - $third = \app\api\model\Third::where('user_id',$user['id'])->field('session_key')->find(); 179 + $user = $this->auth->getUser();
  180 + $third = \app\api\model\Third::where('user_id', $user['id'])->field('session_key')->find();
181 empty($third) && $this->error('请先登录'); 181 empty($third) && $this->error('请先登录');
182 // 获取小程序配置 182 // 获取小程序配置
183 $app = Factory::miniProgram([ 183 $app = Factory::miniProgram([
@@ -188,7 +188,7 @@ class User extends Api @@ -188,7 +188,7 @@ class User extends Api
188 // 更新手机号 188 // 更新手机号
189 $user->mobile = $res['purePhoneNumber']; 189 $user->mobile = $res['purePhoneNumber'];
190 $user->save(); 190 $user->save();
191 - $this->success('授权成功',['mobile' => $res['purePhoneNumber']]); 191 + $this->success('授权成功', ['mobile' => $res['purePhoneNumber']]);
192 } 192 }
193 193
194 /** 194 /**
@@ -200,18 +200,18 @@ class User extends Api @@ -200,18 +200,18 @@ class User extends Api
200 'code':'1', 200 'code':'1',
201 'msg':'返回成功' 201 'msg':'返回成功'
202 "data": [ 202 "data": [
203 - {  
204 - "id": 1,  
205 - "user_id": 1,  
206 - "coupon_id": 1,  
207 - "name": "手动阀手动阀",  
208 - "price": "1.00", 优惠券金额  
209 - "full_price": "10.00", 满减金额  
210 - "createtime": 111122244,  
211 - "endtime": 1641869388,  
212 - "status": "0",  
213 - "endtime_text": "2022年01月11日到期"  
214 - } 203 + {
  204 + "id": 1,
  205 + "user_id": 1,
  206 + "coupon_id": 1,
  207 + "name": "手动阀手动阀",
  208 + "price": "1.00", 优惠券金额
  209 + "full_price": "10.00", 满减金额
  210 + "createtime": 111122244,
  211 + "endtime": 1641869388,
  212 + "status": "0",
  213 + "endtime_text": "2022年01月11日到期"
  214 + }
215 ] 215 ]
216 }) 216 })
217 */ 217 */
@@ -220,12 +220,12 @@ class User extends Api @@ -220,12 +220,12 @@ class User extends Api
220 $model = new UserCoupon(); 220 $model = new UserCoupon();
221 221
222 // 更新已过期状态 222 // 更新已过期状态
223 - $model->where('status','0')->where('user_id',$this->auth->id)->where('endtime','<',time())->update(['status'=>'2']); 223 + $model->where('status', '0')->where('user_id', $this->auth->id)->where('endtime', '<', time())->update(['status' => '2']);
224 224
225 $type = $this->request->post('type'); 225 $type = $this->request->post('type');
226 - if (!in_array($type,[0,1,2])) $this->error('type参数不合法');  
227 - $list = $model->where('status',$type)->where('user_id',$this->auth->id)->select();  
228 - $this->success('用户优惠券列表',$list); 226 + if (!in_array($type, [0, 1, 2])) $this->error('type参数不合法');
  227 + $list = $model->where('status', $type)->where('user_id', $this->auth->id)->select();
  228 + $this->success('用户优惠券列表', $list);
229 } 229 }
230 230
231 /** 231 /**
@@ -236,27 +236,27 @@ class User extends Api @@ -236,27 +236,27 @@ class User extends Api
236 'code':'1', 236 'code':'1',
237 'msg':'返回成功' 237 'msg':'返回成功'
238 "data": [ 238 "data": [
239 - {  
240 - "id": 1,  
241 - "user_id": 1,  
242 - "username": "1", 收件人  
243 - "address": "阿松大", 地址  
244 - "address_detail": "阿松大", 详细地址  
245 - "normal_status": "0", 0不默认1默认  
246 - "lng": null, 经度  
247 - "lat": null, 纬度  
248 - "createtime": null,  
249 - "mobile_hide": "135****9988" 电话号码  
250 - "mobile": "13549059988" 电话号码  
251 - } 239 + {
  240 + "id": 1,
  241 + "user_id": 1,
  242 + "username": "1", 收件人
  243 + "address": "阿松大", 地址
  244 + "address_detail": "阿松大", 详细地址
  245 + "normal_status": "0", 0不默认1默认
  246 + "lng": null, 经度
  247 + "lat": null, 纬度
  248 + "createtime": null,
  249 + "mobile_hide": "135****9988" 电话号码
  250 + "mobile": "13549059988" 电话号码
  251 + }
252 ] 252 ]
253 }) 253 })
254 */ 254 */
255 public function userAddressList() 255 public function userAddressList()
256 { 256 {
257 $model = new UserAddress(); 257 $model = new UserAddress();
258 - $list = $model->where('user_id',$this->auth->id)->order('normal_status','desc')->select();  
259 - $this->success('用户地址列表',$list); 258 + $list = $model->where('user_id', $this->auth->id)->order('normal_status', 'desc')->select();
  259 + $this->success('用户地址列表', $list);
260 } 260 }
261 261
262 262
@@ -281,58 +281,58 @@ class User extends Api @@ -281,58 +281,58 @@ class User extends Api
281 */ 281 */
282 public function userAddressEdit() 282 public function userAddressEdit()
283 { 283 {
284 - $id = $this->request->post('id');  
285 - $type = $this->request->post('type');  
286 - $username = $this->request->post('username');  
287 - $mobile = $this->request->post('mobile');  
288 - $address = $this->request->post('address'); 284 + $id = $this->request->post('id');
  285 + $type = $this->request->post('type');
  286 + $username = $this->request->post('username');
  287 + $mobile = $this->request->post('mobile');
  288 + $address = $this->request->post('address');
289 $address_detail = $this->request->post('address_detail'); 289 $address_detail = $this->request->post('address_detail');
290 - $normal = $this->request->post('normal');  
291 - $lat = $this->request->post('lat');  
292 - $lng = $this->request->post('lng');  
293 - $data = [  
294 - 'type' => $type, 290 + $normal = $this->request->post('normal');
  291 + $lat = $this->request->post('lat');
  292 + $lng = $this->request->post('lng');
  293 + $data = [
  294 + 'type' => $type,
295 'mobile' => $mobile, 295 'mobile' => $mobile,
296 - 'id' => $id, 296 + 'id' => $id,
297 'normal' => $normal, 297 'normal' => $normal,
298 - 'lat' => $lat,  
299 - 'lng' => $lng, 298 + 'lat' => $lat,
  299 + 'lng' => $lng,
300 ]; 300 ];
301 - $rule = [  
302 - 'type' => 'require|in:1,2', 301 + $rule = [
  302 + 'type' => 'require|in:1,2',
303 'mobile' => 'regex:^1\d{10}$', 303 'mobile' => 'regex:^1\d{10}$',
304 - 'id' => 'require|integer', 304 + 'id' => 'require|integer',
305 'normal' => 'in:0,1', 305 'normal' => 'in:0,1',
306 - 'lat' => 'float',  
307 - 'lng' => 'float', 306 + 'lat' => 'float',
  307 + 'lng' => 'float',
308 ]; 308 ];
309 - $msg = [  
310 - 'type' => 'type参数不合法', 309 + $msg = [
  310 + 'type' => 'type参数不合法',
311 'mobile' => '电话号码格式不正确', 311 'mobile' => '电话号码格式不正确',
312 - 'id' => '地址id不合法', 312 + 'id' => '地址id不合法',
313 'normal' => '默认状态参数不合法', 313 'normal' => '默认状态参数不合法',
314 - 'lat' => '纬度请为浮点数格式',  
315 - 'lng' => '经度请为浮点数格式', 314 + 'lat' => '纬度请为浮点数格式',
  315 + 'lng' => '经度请为浮点数格式',
316 ]; 316 ];
317 - $validate = new \think\Validate(); 317 + $validate = new \think\Validate();
318 $validate->rule($rule); 318 $validate->rule($rule);
319 $validate->message($msg); 319 $validate->message($msg);
320 if (!$validate->check($data)) $this->error($validate->getError()); 320 if (!$validate->check($data)) $this->error($validate->getError());
321 $model = new UserAddress(); 321 $model = new UserAddress();
322 - if ($type == 1){ 322 + if ($type == 1) {
323 $data = [ 323 $data = [
324 - 'mobile' => $mobile,  
325 - 'normal_status' => $normal,  
326 - 'lat' => $lat,  
327 - 'lng' => $lng,  
328 - 'username' => $username,  
329 - 'address' => $address, 324 + 'mobile' => $mobile,
  325 + 'normal_status' => $normal,
  326 + 'lat' => $lat,
  327 + 'lng' => $lng,
  328 + 'username' => $username,
  329 + 'address' => $address,
330 'address_detail' => $address_detail, 330 'address_detail' => $address_detail,
331 ]; 331 ];
332 - if ($normal == 1) $model->isUpdate()->save(['normal_status'=>'0'],['user_id'=>$this->auth->id]);  
333 - $model->isUpdate()->save($data,['id'=>$id]);  
334 - }else{  
335 - $model->where('id',$id)->delete(); 332 + if ($normal == 1) $model->isUpdate()->save(['normal_status' => '0'], ['user_id' => $this->auth->id]);
  333 + $model->isUpdate()->save($data, ['id' => $id]);
  334 + } else {
  335 + $model->where('id', $id)->delete();
336 } 336 }
337 $this->success('SUCCESS'); 337 $this->success('SUCCESS');
338 } 338 }
@@ -356,53 +356,53 @@ class User extends Api @@ -356,53 +356,53 @@ class User extends Api
356 */ 356 */
357 public function userAddressAdd() 357 public function userAddressAdd()
358 { 358 {
359 - $username = $this->request->post('username');  
360 - $mobile = $this->request->post('mobile');  
361 - $address = $this->request->post('address'); 359 + $username = $this->request->post('username');
  360 + $mobile = $this->request->post('mobile');
  361 + $address = $this->request->post('address');
362 $address_detail = $this->request->post('address_detail'); 362 $address_detail = $this->request->post('address_detail');
363 - $normal = $this->request->post('normal');  
364 - $lat = $this->request->post('lat');  
365 - $lng = $this->request->post('lng');  
366 - $data = [  
367 - 'mobile' => $mobile, 363 + $normal = $this->request->post('normal');
  364 + $lat = $this->request->post('lat');
  365 + $lng = $this->request->post('lng');
  366 + $data = [
  367 + 'mobile' => $mobile,
368 'username' => $username, 368 'username' => $username,
369 - 'address' => $address,  
370 - 'normal' => $normal,  
371 - 'lat' => $lat,  
372 - 'lng' => $lng, 369 + 'address' => $address,
  370 + 'normal' => $normal,
  371 + 'lat' => $lat,
  372 + 'lng' => $lng,
373 ]; 373 ];
374 - $rule = [  
375 - 'mobile' => 'require|regex:^1\d{10}$', 374 + $rule = [
  375 + 'mobile' => 'require|regex:^1\d{10}$',
376 'username' => 'require', 376 'username' => 'require',
377 - 'address' => 'require',  
378 - 'normal' => 'require|in:0,1',  
379 - 'lat' => 'require|float',  
380 - 'lng' => 'require|float', 377 + 'address' => 'require',
  378 + 'normal' => 'require|in:0,1',
  379 + 'lat' => 'require|float',
  380 + 'lng' => 'require|float',
381 ]; 381 ];
382 - $msg = [  
383 - 'mobile' => '请正确填写电话号码', 382 + $msg = [
  383 + 'mobile' => '请正确填写电话号码',
384 'username' => '请填写收件人', 384 'username' => '请填写收件人',
385 - 'address' => '请选择地址',  
386 - 'normal' => '默认状态参数不合法',  
387 - 'lat' => '请上传纬度且为浮点数格式',  
388 - 'lng' => '请上传经度且为浮点数格式', 385 + 'address' => '请选择地址',
  386 + 'normal' => '默认状态参数不合法',
  387 + 'lat' => '请上传纬度且为浮点数格式',
  388 + 'lng' => '请上传经度且为浮点数格式',
389 ]; 389 ];
390 - $validate = new \think\Validate(); 390 + $validate = new \think\Validate();
391 $validate->rule($rule); 391 $validate->rule($rule);
392 $validate->message($msg); 392 $validate->message($msg);
393 if (!$validate->check($data)) $this->error($validate->getError()); 393 if (!$validate->check($data)) $this->error($validate->getError());
394 $model = new UserAddress(); 394 $model = new UserAddress();
395 - $data = [  
396 - 'mobile' => $mobile,  
397 - 'user_id' => $this->auth->id,  
398 - 'normal_status' => $normal,  
399 - 'lat' => $lat,  
400 - 'lng' => $lng,  
401 - 'username' => $username,  
402 - 'address' => $address, 395 + $data = [
  396 + 'mobile' => $mobile,
  397 + 'user_id' => $this->auth->id,
  398 + 'normal_status' => $normal,
  399 + 'lat' => $lat,
  400 + 'lng' => $lng,
  401 + 'username' => $username,
  402 + 'address' => $address,
403 'address_detail' => $address_detail, 403 'address_detail' => $address_detail,
404 ]; 404 ];
405 - if ($normal == 1) $model->isUpdate()->save(['normal_status'=>'0'],['user_id'=>$this->auth->id]); 405 + if ($normal == 1) $model->isUpdate()->save(['normal_status' => '0'], ['user_id' => $this->auth->id]);
406 $model->isUpdate(false)->save($data); 406 $model->isUpdate(false)->save($data);
407 407
408 $this->success('SUCCESS'); 408 $this->success('SUCCESS');
@@ -428,43 +428,43 @@ class User extends Api @@ -428,43 +428,43 @@ class User extends Api
428 */ 428 */
429 public function joinUs() 429 public function joinUs()
430 { 430 {
431 - $work = $this->request->post('work');  
432 - $years = $this->request->post('years'); 431 + $work = $this->request->post('work');
  432 + $years = $this->request->post('years');
433 $username = $this->request->post('username'); 433 $username = $this->request->post('username');
434 - $mobile = $this->request->post('mobile');  
435 - $money = $this->request->post('money');  
436 - $team = $this->request->post('team');  
437 - $city = $this->request->post('city');  
438 - $content = $this->request->post('content');  
439 - $data = [  
440 - 'work' => $work,  
441 - 'mobile' => $mobile, 434 + $mobile = $this->request->post('mobile');
  435 + $money = $this->request->post('money');
  436 + $team = $this->request->post('team');
  437 + $city = $this->request->post('city');
  438 + $content = $this->request->post('content');
  439 + $data = [
  440 + 'work' => $work,
  441 + 'mobile' => $mobile,
442 'username' => $username, 442 'username' => $username,
443 - 'years' => $years,  
444 - 'money' => $money,  
445 - 'team' => $team,  
446 - 'city' => $city,  
447 - 'content' => $content, 443 + 'years' => $years,
  444 + 'money' => $money,
  445 + 'team' => $team,
  446 + 'city' => $city,
  447 + 'content' => $content,
448 ]; 448 ];
449 - $rule = [  
450 - 'work' => 'require',  
451 - 'mobile' => 'require|regex:^1\d{10}$',  
452 - 'years' => 'require', 449 + $rule = [
  450 + 'work' => 'require',
  451 + 'mobile' => 'require|regex:^1\d{10}$',
  452 + 'years' => 'require',
453 'username' => 'require', 453 'username' => 'require',
454 - 'money' => 'require',  
455 - 'team' => 'require|in:0,1',  
456 - 'city' => 'require',  
457 - 'content' => 'require|max:100', 454 + 'money' => 'require',
  455 + 'team' => 'require|in:0,1',
  456 + 'city' => 'require',
  457 + 'content' => 'require|max:100',
458 ]; 458 ];
459 - $msg = [  
460 - 'work' => '请填写从事行业',  
461 - 'mobile' => '请正确填写电话号码',  
462 - 'years' => '请填写从业时间', 459 + $msg = [
  460 + 'work' => '请填写从事行业',
  461 + 'mobile' => '请正确填写电话号码',
  462 + 'years' => '请填写从业时间',
463 'username' => '请输入姓名', 463 'username' => '请输入姓名',
464 - 'money' => '请输入可投入资金',  
465 - 'team' => '请选择是否拥有团队',  
466 - 'city' => '请填写意向城市',  
467 - 'content' => '请填写描述控制在100字以内', 464 + 'money' => '请输入可投入资金',
  465 + 'team' => '请选择是否拥有团队',
  466 + 'city' => '请填写意向城市',
  467 + 'content' => '请填写描述控制在100字以内',
468 ]; 468 ];
469 $validate = new \think\Validate(); 469 $validate = new \think\Validate();
470 $validate->rule($rule); 470 $validate->rule($rule);
@@ -472,8 +472,8 @@ class User extends Api @@ -472,8 +472,8 @@ class User extends Api
472 if (!$validate->check($data)) $this->error($validate->getError()); 472 if (!$validate->check($data)) $this->error($validate->getError());
473 473
474 // 禁止连点 474 // 禁止连点
475 - !empty(cache('joinus_'.$username)) && $this->error('操作频繁,请稍后再试');  
476 - cache('joinus_'.$username,'123',5); 475 + !empty(cache('joinus_' . $username)) && $this->error('操作频繁,请稍后再试');
  476 + cache('joinus_' . $username, '123', 5);
477 477
478 $data['createtime'] = time(); 478 $data['createtime'] = time();
479 Db::name('join_us')->insert($data); 479 Db::name('join_us')->insert($data);
@@ -490,21 +490,21 @@ class User extends Api @@ -490,21 +490,21 @@ class User extends Api
490 'code':'1', 490 'code':'1',
491 'msg':'SUCCESS' 491 'msg':'SUCCESS'
492 "data": 492 "data":
493 - "list": {  
494 - "total": 1,  
495 - "per_page": 15,  
496 - "current_page": 1,  
497 - "last_page": 1,  
498 - "data": [  
499 - {  
500 - "id": 1,  
501 - "title": "123", 标题  
502 - "content": "啊实打实大苏打", 内容  
503 - }  
504 - ]  
505 - },  
506 - "rider_status": 0 申请骑手状态:0=无,1=申请中,2=成功,3=拒绝  
507 - "mobile": 拨号电话号码 493 + "list": {
  494 + "total": 1,
  495 + "per_page": 15,
  496 + "current_page": 1,
  497 + "last_page": 1,
  498 + "data": [
  499 + {
  500 + "id": 1,
  501 + "title": "123", 标题
  502 + "content": "啊实打实大苏打", 内容
  503 + }
  504 + ]
  505 + },
  506 + "rider_status": 0 申请骑手状态:0=无,1=申请中,2=成功,3=拒绝
  507 + "mobile": 拨号电话号码
508 }) 508 })
509 */ 509 */
510 public function helpsList() 510 public function helpsList()
@@ -512,9 +512,9 @@ class User extends Api @@ -512,9 +512,9 @@ class User extends Api
512 $page = $this->request->post('page'); 512 $page = $this->request->post('page');
513 if (!is_numeric($page)) $this->error('页数参数不合法'); 513 if (!is_numeric($page)) $this->error('页数参数不合法');
514 $list = Db::name('helps') 514 $list = Db::name('helps')
515 - ->order('id','desc')  
516 - ->paginate(15,false,['page'=>$page]);  
517 - $this->success('SUCCESS',['list'=>$list,'rider_status'=>$this->auth->rider,'mobile'=>Config::get('site.work_mobile')]); 515 + ->order('id', 'desc')
  516 + ->paginate(15, false, ['page' => $page]);
  517 + $this->success('SUCCESS', ['list' => $list, 'rider_status' => $this->auth->rider, 'mobile' => Config::get('site.work_mobile')]);
518 } 518 }
519 519
520 /** 520 /**
@@ -537,13 +537,13 @@ class User extends Api @@ -537,13 +537,13 @@ class User extends Api
537 $mobile = $this->request->post('mobile'); 537 $mobile = $this->request->post('mobile');
538 if (!$cotent) $this->error('请填写意见描述'); 538 if (!$cotent) $this->error('请填写意见描述');
539 if (mb_strlen($cotent) > 100) $this->error('请将意见描述控制在100字以内'); 539 if (mb_strlen($cotent) > 100) $this->error('请将意见描述控制在100字以内');
540 - if (!$mobile || !preg_match('/^1\d{10}$/',$mobile)) $this->error('请正确填写联系方式'); 540 + if (!$mobile || !preg_match('/^1\d{10}$/', $mobile)) $this->error('请正确填写联系方式');
541 $data = [ 541 $data = [
542 - 'user_id' => $this->auth->id,  
543 - 'cotent' => $cotent,  
544 - 'images' => $images,  
545 - 'mobile' => $mobile,  
546 - 'createtime' => time() 542 + 'user_id' => $this->auth->id,
  543 + 'cotent' => $cotent,
  544 + 'images' => $images,
  545 + 'mobile' => $mobile,
  546 + 'createtime' => time(),
547 ]; 547 ];
548 Db::name('opinion')->insert($data); 548 Db::name('opinion')->insert($data);
549 $this->success('SUCCESS'); 549 $this->success('SUCCESS');
@@ -561,10 +561,10 @@ class User extends Api @@ -561,10 +561,10 @@ class User extends Api
561 */ 561 */
562 public function riderApply() 562 public function riderApply()
563 { 563 {
564 - if (in_array($this->auth->rider,[1,2])){ 564 + if (in_array($this->auth->rider, [1, 2])) {
565 $this->error('您已申请,不可重复申请'); 565 $this->error('您已申请,不可重复申请');
566 } 566 }
567 - $user = $this->auth->getUser(); 567 + $user = $this->auth->getUser();
568 $user->rider = '1'; 568 $user->rider = '1';
569 $user->save(); 569 $user->save();
570 $this->success('SUCCESS'); 570 $this->success('SUCCESS');
@@ -578,38 +578,38 @@ class User extends Api @@ -578,38 +578,38 @@ class User extends Api
578 'code':'1', 578 'code':'1',
579 'msg':'邀请有奖' 579 'msg':'邀请有奖'
580 "data": 580 "data":
581 - "price": "10.00", 优惠价格  
582 - "full_price": "100.00", 满减价格  
583 - "endtime": "2022年04月10日", 到期时间  
584 - "rule": "啊实打实大苏打", 规则  
585 - "user_list": [  
586 - {  
587 - "user": {  
588 - "nickname": "admin",  
589 - "avatar_text": ""  
590 - },  
591 - "createtime_text": ""  
592 - }  
593 - ],  
594 - "invite_id": 1, 邀请人id 581 + "price": "10.00", 优惠价格
  582 + "full_price": "100.00", 满减价格
  583 + "endtime": "2022年04月10日", 到期时间
  584 + "rule": "啊实打实大苏打", 规则
  585 + "user_list": [
  586 + {
  587 + "user": {
  588 + "nickname": "admin",
  589 + "avatar_text": ""
  590 + },
  591 + "createtime_text": ""
  592 + }
  593 + ],
  594 + "invite_id": 1, 邀请人id
595 }) 595 })
596 */ 596 */
597 public function inviteReward() 597 public function inviteReward()
598 { 598 {
599 - $model = new \app\api\model\User();  
600 - $coupon = Db::name('coupon')->where('id',1)->field('price,full_price,endtime')->find();  
601 - $coupon['endtime'] = date('Y年m月d日',$coupon['endtime']);  
602 - $coupon['rule'] = Config::get('site.invite_rule'); 599 + $model = new \app\api\model\User();
  600 + $coupon = Db::name('coupon')->where('id', 1)->field('price,full_price,endtime')->find();
  601 + $coupon['endtime'] = date('Y年m月d日', $coupon['endtime']);
  602 + $coupon['rule'] = Config::get('site.invite_rule');
603 $coupon['user_list'] = $model 603 $coupon['user_list'] = $model
604 - ->where('invite_user_id',$this->auth->id)  
605 - ->where('invite_status','1') 604 + ->where('invite_user_id', $this->auth->id)
  605 + ->where('invite_status', '1')
606 ->limit(3) 606 ->limit(3)
607 ->select(); 607 ->select();
608 - foreach ($coupon['user_list'] as $key => $value){ 608 + foreach ($coupon['user_list'] as $key => $value) {
609 $value->visible(['nickname']); 609 $value->visible(['nickname']);
610 } 610 }
611 $coupon['invite_id'] = $this->auth->id; 611 $coupon['invite_id'] = $this->auth->id;
612 - $this->success('邀请有奖',$coupon); 612 + $this->success('邀请有奖', $coupon);
613 } 613 }
614 614
615 /** 615 /**
@@ -621,34 +621,34 @@ class User extends Api @@ -621,34 +621,34 @@ class User extends Api
621 'code':'1', 621 'code':'1',
622 'msg':'发票管理列表' 622 'msg':'发票管理列表'
623 "data": 623 "data":
624 - "total": 1, 总条数  
625 - "per_page": 5, 每页数量  
626 - "current_page": 1, 当前页  
627 - "last_page": 1, 最后一页  
628 - "data": [  
629 - {  
630 - "id": "1",  
631 - "company_name": "asdsd", 公司名称  
632 - "username": "asdsa", 个人名称  
633 - "type": "1", 1个人发票2公司发票  
634 - "price": 0, 发票价格  
635 - "tax_time": 1654891234,  
636 - "tax_time_text": "2022年01月12日" 开票时间  
637 - }  
638 - ] 624 + "total": 1, 总条数
  625 + "per_page": 5, 每页数量
  626 + "current_page": 1, 当前页
  627 + "last_page": 1, 最后一页
  628 + "data": [
  629 + {
  630 + "id": "1",
  631 + "company_name": "asdsd", 公司名称
  632 + "username": "asdsa", 个人名称
  633 + "type": "1", 1个人发票2公司发票
  634 + "price": 0, 发票价格
  635 + "tax_time": 1654891234,
  636 + "tax_time_text": "2022年01月12日" 开票时间
  637 + }
  638 + ]
639 }) 639 })
640 */ 640 */
641 public function taxList() 641 public function taxList()
642 { 642 {
643 - $page = $this->request->post('page',1); 643 + $page = $this->request->post('page', 1);
644 $model = new Tax(); 644 $model = new Tax();
645 - $list = $model  
646 - ->where('user_id',$this->auth->id)  
647 - ->where('del_status','normal') 645 + $list = $model
  646 + ->where('user_id', $this->auth->id)
  647 + ->where('del_status', 'normal')
648 ->field('id,company_name,username,type,price,tax_time') 648 ->field('id,company_name,username,type,price,tax_time')
649 - ->order('id','desc')  
650 - ->paginate(5,false,['page'=>$page]);  
651 - $this->success('发票管理列表',$list); 649 + ->order('id', 'desc')
  650 + ->paginate(5, false, ['page' => $page]);
  651 + $this->success('发票管理列表', $list);
652 } 652 }
653 653
654 654
@@ -675,92 +675,92 @@ class User extends Api @@ -675,92 +675,92 @@ class User extends Api
675 */ 675 */
676 public function taxApply() 676 public function taxApply()
677 { 677 {
678 - $type = $this->request->post('type');  
679 - $username = $this->request->post('username');  
680 - $company_name = $this->request->post('company_name');  
681 - $tax_number = $this->request->post('tax_number'); 678 + $type = $this->request->post('type');
  679 + $username = $this->request->post('username');
  680 + $company_name = $this->request->post('company_name');
  681 + $tax_number = $this->request->post('tax_number');
682 $company_address = $this->request->post('company_address'); 682 $company_address = $this->request->post('company_address');
683 - $company_mobile = $this->request->post('company_mobile');  
684 - $bank = $this->request->post('bank');  
685 - $mobile = $this->request->post('mobile');  
686 - $eamil = $this->request->post('eamil');  
687 - $order_no = $this->request->post('order_no'); 683 + $company_mobile = $this->request->post('company_mobile');
  684 + $bank = $this->request->post('bank');
  685 + $mobile = $this->request->post('mobile');
  686 + $eamil = $this->request->post('eamil');
  687 + $order_no = $this->request->post('order_no');
688 //校验数据 688 //校验数据
689 - if (!in_array($type,[1,2])) $this->error('type参数不合法');  
690 - $data = [  
691 - 'mobile' => $mobile,  
692 - 'eamil' => $eamil, 689 + if (!in_array($type, [1, 2])) $this->error('type参数不合法');
  690 + $data = [
  691 + 'mobile' => $mobile,
  692 + 'eamil' => $eamil,
693 'order_no' => $order_no, 693 'order_no' => $order_no,
694 ]; 694 ];
695 - $rule = [  
696 - 'mobile' => 'regex:^1\d{10}$',  
697 - 'eamil' => 'regex:^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$', 695 + $rule = [
  696 + 'mobile' => 'regex:^1\d{10}$',
  697 + 'eamil' => 'regex:^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$',
698 'order_no' => 'require', 698 'order_no' => 'require',
699 ]; 699 ];
700 - $msg = [  
701 - 'mobile' => '收票人电话号码格式不正确',  
702 - 'eamil' => '电子邮箱格式不正确', 700 + $msg = [
  701 + 'mobile' => '收票人电话号码格式不正确',
  702 + 'eamil' => '电子邮箱格式不正确',
703 'order_no' => '请输入订单编号', 703 'order_no' => '请输入订单编号',
704 ]; 704 ];
705 - $validate = new \think\Validate($rule,$msg); 705 + $validate = new \think\Validate($rule, $msg);
706 if (!$validate->check($data)) $this->error($validate->getError()); 706 if (!$validate->check($data)) $this->error($validate->getError());
707 - if ($type == 2){  
708 - $data = [  
709 - 'company_name' => $company_name,  
710 - 'company_mobile' => $company_mobile,  
711 - 'tax_number' => $tax_number, 707 + if ($type == 2) {
  708 + $data = [
  709 + 'company_name' => $company_name,
  710 + 'company_mobile' => $company_mobile,
  711 + 'tax_number' => $tax_number,
712 'company_address' => $company_address, 712 'company_address' => $company_address,
713 - 'bank' => $bank, 713 + 'bank' => $bank,
714 ]; 714 ];
715 - $rule = [  
716 - 'company_name' => 'require',  
717 - 'tax_number' => 'require', 715 + $rule = [
  716 + 'company_name' => 'require',
  717 + 'tax_number' => 'require',
718 'company_address' => 'require', 718 'company_address' => 'require',
719 - 'bank' => 'require',  
720 - 'company_mobile' => 'regex:^1\d{10}$', 719 + 'bank' => 'require',
  720 + 'company_mobile' => 'regex:^1\d{10}$',
721 ]; 721 ];
722 - $msg = [  
723 - 'company_mobile' => '公司电话格式不正确',  
724 - 'company_name' => '请填写公司名称',  
725 - 'tax_number' => '请填写纳税人识别号', 722 + $msg = [
  723 + 'company_mobile' => '公司电话格式不正确',
  724 + 'company_name' => '请填写公司名称',
  725 + 'tax_number' => '请填写纳税人识别号',
726 'company_address' => '请填写公司地址', 726 'company_address' => '请填写公司地址',
727 - 'bank' => '请填写开户银行', 727 + 'bank' => '请填写开户银行',
728 ]; 728 ];
729 - $validate = new \think\Validate($rule,$msg); 729 + $validate = new \think\Validate($rule, $msg);
730 if (!$validate->check($data)) $this->error($validate->getError()); 730 if (!$validate->check($data)) $this->error($validate->getError());
731 - }else{  
732 - $data = [ 731 + } else {
  732 + $data = [
733 'username' => $username, 733 'username' => $username,
734 ]; 734 ];
735 - $rule = [ 735 + $rule = [
736 'username' => 'require', 736 'username' => 'require',
737 ]; 737 ];
738 - $msg = [ 738 + $msg = [
739 'username' => '请填写个人/非企业单位名称', 739 'username' => '请填写个人/非企业单位名称',
740 ]; 740 ];
741 - $validate = new \think\Validate($rule,$msg); 741 + $validate = new \think\Validate($rule, $msg);
742 if (!$validate->check($data)) $this->error($validate->getError()); 742 if (!$validate->check($data)) $this->error($validate->getError());
743 } 743 }
744 //校验订单编号 744 //校验订单编号
745 $orderModel = new \app\api\model\Order(); 745 $orderModel = new \app\api\model\Order();
746 - $order = $orderModel::get(['order_no'=>$order_no]); 746 + $order = $orderModel::get(['order_no' => $order_no]);
747 if (!$order) $this->error('订单编号不存在'); 747 if (!$order) $this->error('订单编号不存在');
748 if ($order['user_id'] != $this->auth->id) $this->error('当前用户无权使用此订单编号'); 748 if ($order['user_id'] != $this->auth->id) $this->error('当前用户无权使用此订单编号');
749 // 插入数据 749 // 插入数据
750 - $data = [  
751 - 'company_name' => $company_name,  
752 - 'username' => $username,  
753 - 'company_mobile' => $company_mobile,  
754 - 'tax_number' => $tax_number, 750 + $data = [
  751 + 'company_name' => $company_name,
  752 + 'username' => $username,
  753 + 'company_mobile' => $company_mobile,
  754 + 'tax_number' => $tax_number,
755 'company_address' => $company_address, 755 'company_address' => $company_address,
756 - 'bank' => $bank,  
757 - 'mobile' => $mobile,  
758 - 'email' => $eamil,  
759 - 'order_no' => $order_no,  
760 - 'type' => $type,  
761 - 'order_id' => $order['id'],  
762 - 'price' => $order['total_price'],  
763 - 'user_id' => $this->auth->id, 756 + 'bank' => $bank,
  757 + 'mobile' => $mobile,
  758 + 'email' => $eamil,
  759 + 'order_no' => $order_no,
  760 + 'type' => $type,
  761 + 'order_id' => $order['id'],
  762 + 'price' => $order['total_price'],
  763 + 'user_id' => $this->auth->id,
764 ]; 764 ];
765 $model = new Tax(); 765 $model = new Tax();
766 $model->allowField(true)->isUpdate(false)->save($data); 766 $model->allowField(true)->isUpdate(false)->save($data);
@@ -783,28 +783,28 @@ class User extends Api @@ -783,28 +783,28 @@ class User extends Api
783 { 783 {
784 $ids = $this->request->post('ids'); 784 $ids = $this->request->post('ids');
785 //校验数据 785 //校验数据
786 - $ids = explode(',',$ids);  
787 - foreach ($ids as $key => $value){ 786 + $ids = explode(',', $ids);
  787 + foreach ($ids as $key => $value) {
788 if (!is_numeric($value)) $this->error('ids参数不合法'); 788 if (!is_numeric($value)) $this->error('ids参数不合法');
789 } 789 }
790 $model = new Tax(); 790 $model = new Tax();
791 - $model->isUpdate()->save(['del_status' => 'hidden'],['id' => ['in',$ids]]); 791 + $model->isUpdate()->save(['del_status' => 'hidden'], ['id' => ['in', $ids]]);
792 $this->success('SUCCESS'); 792 $this->success('SUCCESS');
793 } 793 }
794 794
795 /** 795 /**
796 * 开发登录 796 * 开发登录
797 * @ApiMethod (POST) 797 * @ApiMethod (POST)
798 - * @param string $account 账号 798 + * @param string $account 账号
799 */ 799 */
800 public function developLogin() 800 public function developLogin()
801 { 801 {
802 - $account = $this->request->post('account'); 802 + $account = $this->request->param('account');
803 if (!$account) { 803 if (!$account) {
804 $this->error(__('Invalid parameters')); 804 $this->error(__('Invalid parameters'));
805 } 805 }
806 $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username'); 806 $field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username');
807 - $user = \app\common\model\User::get([$field => $account]); 807 + $user = \app\common\model\User::get([$field => $account]);
808 if (!$user) { 808 if (!$user) {
809 $this->error('账号格式不正确'); 809 $this->error('账号格式不正确');
810 } 810 }
@@ -821,14 +821,15 @@ class User extends Api @@ -821,14 +821,15 @@ class User extends Api
821 * 测试 821 * 测试
822 * @ApiInternal 822 * @ApiInternal
823 */ 823 */
824 - public function notice(){  
825 - $client = new Client();  
826 - $response = $client->request('POST', request()->domain().":2121/", [ 824 + public function notice()
  825 + {
  826 + $client = new Client();
  827 + $response = $client->request('POST', request()->domain() . ":2121/", [
827 'form_params' => [ 828 'form_params' => [
828 - 'type' => 'publish', 829 + 'type' => 'publish',
829 'content' => '这个是推送的测试数据', 830 'content' => '这个是推送的测试数据',
830 - 'to' => '',  
831 - ] 831 + 'to' => '',
  832 + ],
832 ]); 833 ]);
833 halt($response->getBody()->getContents()); 834 halt($response->getBody()->getContents());
834 } 835 }