作者 李忠强

更新

  1 +<?php
  2 +
  3 +
  4 +namespace app\api\controller;
  5 +
  6 +
  7 +use app\common\controller\Api;
  8 +use think\Config;
  9 +use think\Db;
  10 +
  11 +/**
  12 + * 首页活动
  13 + */
  14 +class Activity extends Api
  15 +{
  16 + protected $noNeedRight = ['*'];
  17 + protected $noNeedLogin = ['*'];
  18 +
  19 + /**
  20 + * @ApiTitle (活动名称列表)
  21 + * @ApiMethod (POST)
  22 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  23 + * @ApiParams (name="id", type="integer", required=true, description="活动ID")
  24 + * @ApiParams (name="page", type="integer", required=true, description="页数")
  25 + * @ApiReturn ({
  26 + 'code':'1',
  27 + 'msg':'返回成功'
  28 + 'data':
  29 + "list": {
  30 + "total": 4, 总条数
  31 + "per_page": 10,每页数量
  32 + "current_page": 1,当前页
  33 + "last_page": 1,最后一页
  34 + "data": [
  35 + {
  36 + "goods_id": 21,
  37 + "goods_name": "小米Mix3",
  38 + "price": "100.00",
  39 + "line_price": "1000.00",划线价
  40 + "image_text": "图片路径"
  41 + }
  42 + ]
  43 + },
  44 + "timeslot": "秒杀时间段"
  45 + "image": "广告图"
  46 + })
  47 + */
  48 + public function activity()
  49 + {
  50 +
  51 + $list = Db::name('activity')->select();
  52 + $this->success('活动商品列表',['list'=>$list]);
  53 + }
  54 +
  55 +
  56 + /**
  57 + * @ApiTitle (活动商品列表)
  58 + * @ApiMethod (POST)
  59 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  60 + * @ApiParams (name="id", type="integer", required=true, description="活动ID")
  61 + * @ApiParams (name="page", type="integer", required=true, description="页数")
  62 + * @ApiReturn ({
  63 + 'code':'1',
  64 + 'msg':'返回成功'
  65 + 'data':
  66 + "list": {
  67 + "total": 4, 总条数
  68 + "per_page": 10,每页数量
  69 + "current_page": 1,当前页
  70 + "last_page": 1,最后一页
  71 + "data": [
  72 + {
  73 + "goods_id": 21,
  74 + "goods_name": "小米Mix3",
  75 + "price": "100.00",
  76 + "line_price": "1000.00",划线价
  77 + "image_text": "图片路径"
  78 + }
  79 + ]
  80 + },
  81 + "timeslot": "秒杀时间段"
  82 + {
  83 + "time": "16:41",
  84 + "status": "not" not 未开始 will即将开始 begin 抢购中 over 已结束
  85 + },
  86 + {
  87 + "time": "17:24",
  88 + "status": "not"
  89 + },
  90 + "image": "广告图"
  91 + })
  92 + */
  93 + public function listGoods()
  94 + {
  95 + $id = $this->request->post('id');
  96 + $page = $this->request->post('page',1);
  97 + if (!is_numeric($page) || !is_numeric($id)) $this->error('参数不合法');
  98 + $model = new \app\api\model\Goods();
  99 +
  100 + $list = $model
  101 + ->where('is_delete','0')
  102 + ->where('goods_status','10')
  103 + ->where('activity_id',$id)
  104 + ->field('goods_id,goods_name,image')
  105 + ->paginate(10,false,['page'=>$page])
  106 + ->each(function ($item,$key){
  107 + $goods_spec = Db::name('litestore_goods_spec')
  108 + ->where('goods_id',$item['goods_id'])
  109 + ->find();
  110 + $item['price'] = $goods_spec['goods_price'];
  111 + $item['line_price'] = $goods_spec['line_price'];
  112 + });
  113 + $timeslot = $this->timeplot();
  114 + $image = cdnurl(Config::get('site.activity_image'),true);
  115 + $this->success('活动商品列表',['list'=>$list,'timeslot'=>$timeslot,'image'=>$image]);
  116 + }
  117 +}
@@ -184,7 +184,7 @@ class Goods extends Api @@ -184,7 +184,7 @@ class Goods extends Api
184 } 184 }
185 $model = new GoodsComment(); 185 $model = new GoodsComment();
186 $goods = []; 186 $goods = [];
187 - $goods['comment_number'] = $model->where('status','normal')->count(); 187 + $goods['comment_number'] = $model->where('goods_id',$goods_id)->where('status','normal')->count();
188 $goods['comment'] = $model 188 $goods['comment'] = $model
189 ->with(['user']) 189 ->with(['user'])
190 ->where('goods_id',$goods_id) 190 ->where('goods_id',$goods_id)
@@ -469,4 +469,108 @@ class Order extends Api @@ -469,4 +469,108 @@ class Order extends Api
469 $this->success('支付信息',$result); 469 $this->success('支付信息',$result);
470 } 470 }
471 471
  472 +
  473 + /**
  474 + * @ApiTitle (确认收货)
  475 + * @ApiMethod (POST)
  476 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  477 + * @ApiParams (name="id", type="integer", required=true, description="订单ID")
  478 + * @ApiReturn ({
  479 + 'code':'1',
  480 + 'msg':'返回成功'
  481 + })
  482 + */
  483 + public function takeover()
  484 + {
  485 + $order_id = $this->request->post('id');
  486 + if (!is_numeric($order_id)) $this->error('参数不合法');
  487 +
  488 + $model = new \app\api\model\Order();
  489 + $order = $model::get($order_id);
  490 + if (!$order) $this->error('订单不存在');
  491 + if ($order['receipt_status'] == 20) $this->error('订单已收货,请勿重复提交');
  492 + $order->receipt_status = '20';
  493 + $order->isUpdate()->save();
  494 + $this->success('收货成功');
  495 + }
  496 +
  497 +
  498 + /**
  499 + * @ApiTitle (提醒发货)
  500 + * @ApiMethod (POST)
  501 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  502 + * @ApiParams (name="id", type="integer", required=true, description="订单ID")
  503 + * @ApiReturn ({
  504 + 'code':'1',
  505 + 'msg':'返回成功'
  506 + })
  507 + */
  508 + public function remind()
  509 + {
  510 + $order_id = $this->request->post('id');
  511 + if (!is_numeric($order_id)) $this->error('参数不合法');
  512 +
  513 + $model = new \app\api\model\Order();
  514 + $model->where('id',$order_id)->isUpdate()->save(['remind_status'=>'20']);
  515 + $this->success('提醒成功');
  516 + }
  517 +
  518 +
  519 + /**
  520 + * @ApiTitle (取消订单)
  521 + * @ApiMethod (POST)
  522 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  523 + * @ApiParams (name="id", type="integer", required=true, description="订单ID")
  524 + * @ApiReturn ({
  525 + 'code':'1',
  526 + 'msg':'返回成功'
  527 + })
  528 + */
  529 + public function cancelOrder()
  530 + {
  531 + $order_id = $this->request->post('id');
  532 + if (!is_numeric($order_id)) $this->error('参数不合法');
  533 +
  534 + $model = new \app\api\model\Order();
  535 + $model->where('id',$order_id)->isUpdate()->save(['order_status'=>'20']);
  536 + $this->success('取消成功');
  537 + }
  538 +
  539 + /**
  540 + * @ApiTitle (评价订单)
  541 + * @ApiMethod (POST)
  542 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  543 + * @ApiParams (name="id", type="integer", required=true, description="订单ID")
  544 + * @ApiParams (name="score", type="integer", required=true, description="评价分数")
  545 + * @ApiParams (name="comment", type="string", required=true, description="评价内容")
  546 + * @ApiParams (name="images", type="string", required=true, description="评价图片逗号隔开")
  547 + * @ApiReturn ({
  548 + 'code':'1',
  549 + 'msg':'返回成功'
  550 + })
  551 + */
  552 + public function commentOrder()
  553 + {
  554 + $order_id = $this->request->post('id');
  555 + $score = $this->request->post('score');
  556 + $comment = $this->request->post('comment');
  557 + $images = $this->request->post('images');
  558 + if (!is_numeric($order_id)) $this->error('订单id参数不合法');
  559 + if (!is_numeric($score) || $score>5 || $score<1) $this->error('评价分数不合法');
  560 + if (!$comment) $this->error('请填写评价内容');
  561 + if (!$comment) $this->error('请填写评价内容');
  562 + if ($images){
  563 + $arr = explode(',',$images);
  564 + if (count($arr) > 3) $this->error('请上传最多3张评价图片');
  565 + }
  566 +
  567 + $model = new \app\api\model\Order();
  568 + $model->where('id',$order_id)->isUpdate()->save(['order_status'=>'30']);
  569 +// $data = [
  570 +// 'user_id' => $this->auth->id,
  571 +// 'goods_id' => $
  572 +// ]
  573 + $this->success('取消成功');
  574 + }
  575 +
472 } 576 }
@@ -6,6 +6,8 @@ namespace app\api\controller; @@ -6,6 +6,8 @@ namespace app\api\controller;
6 6
7 use app\api\model\RiderOrder; 7 use app\api\model\RiderOrder;
8 use app\common\controller\Api; 8 use app\common\controller\Api;
  9 +use think\Config;
  10 +use think\Db;
9 11
10 /** 12 /**
11 * 骑手 13 * 骑手
@@ -13,7 +15,7 @@ use app\common\controller\Api; @@ -13,7 +15,7 @@ use app\common\controller\Api;
13 class Rider extends Api 15 class Rider extends Api
14 { 16 {
15 protected $noNeedRight = ['*']; 17 protected $noNeedRight = ['*'];
16 -// protected $noNeedLogin = ['*']; 18 + protected $noNeedLogin = ['*'];
17 19
18 /** 20 /**
19 * @ApiTitle (骑手订单页) 21 * @ApiTitle (骑手订单页)
@@ -142,4 +144,155 @@ class Rider extends Api @@ -142,4 +144,155 @@ class Rider extends Api
142 $data['all_order'] = $allcount; 144 $data['all_order'] = $allcount;
143 $this->success('骑手个人页',$data); 145 $this->success('骑手个人页',$data);
144 } 146 }
  147 +
  148 +
  149 + /**
  150 + * @ApiTitle (骑手订单详情)
  151 + * @ApiMethod (POST)
  152 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  153 + * @ApiHeaders (name=id, type=integer, required=true, description="骑手订单id")
  154 + * @ApiHeaders (name=lat, type=float, required=true, description="纬度")
  155 + * @ApiHeaders (name=lng, type=float, required=true, description="经度")
  156 + * @ApiReturn ({
  157 + 'code':'1',
  158 + 'msg':'返回成功'
  159 + 'data':
  160 + "id": 7,
  161 + "order_no": "LQ-16420622494781", 订单编号
  162 + "distance": 111.3195, 距离
  163 + "address": {
  164 + "id": 1,
  165 + "name": "1", 姓名
  166 + "phone": "13549059988",
  167 + "detail": "阿松大1", 门牌号
  168 + "address": "阿松大", 地址
  169 + "order_id": 7,
  170 + "user_id": 1,
  171 + "lat": "116.397128",
  172 + "lng": "39.916527",
  173 + "createtime": 0,
  174 + "province_id": 1,
  175 + "city_id": 2,
  176 + "region_id": 3,
  177 + "mobile_hide": "135****9988" 电话号码
  178 + },
  179 + "goods": [
  180 + {
  181 + "goods_name": "Mate 20 华为 HUAWEI ",
  182 + "goods_attr": "极光色 8GB+128GB",
  183 + "image_text": "http://temporaryfood.qiniu.broing.cn123132"
  184 + },
  185 + {
  186 + "goods_name": "MacBook Pro 13寸",
  187 + "goods_attr": "天空灰",
  188 + "image_text": "http://temporaryfood.qiniu.broing.cn123132"
  189 + }
  190 + ],
  191 + "createtime_text": ""
  192 + })
  193 + */
  194 + public function orderDetail()
  195 + {
  196 + $id = $this->request->post('id');
  197 + $lat = $this->request->post('lat');
  198 + $lng = $this->request->post('lng');
  199 + $rider_order = RiderOrder::get($id);
  200 + $ordermodel = new \app\api\model\Order();
  201 + $order = $ordermodel
  202 + ->with(['address','goods'])
  203 + ->where('fa_litestore_order.id',$rider_order['order_id'])
  204 + ->find();
  205 + $order->visible(['order_no','address','goods','id','distance']);
  206 + foreach ($order->getRelation('goods') as $key => $value){
  207 + $value->visible(['goods_name','goods_attr']);
  208 + }
  209 + $lat1 = $order['address']['lat'];
  210 + $lng1 = $order['address']['lng'];
  211 + $lat2 = $lat;
  212 + $lng2 = $lng;
  213 + $order['distance'] = getDistance($lat1,$lng1,$lat2,$lng2);
  214 + $this->success('骑手个人页',$order);
  215 + }
  216 +
  217 +
  218 + /**
  219 + * @ApiTitle (骑手已送达)
  220 + * @ApiMethod (POST)
  221 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  222 + * @ApiHeaders (name=id, type=integer, required=true, description="骑手订单id")
  223 + * @ApiReturn ({
  224 + 'code':'1',
  225 + 'msg':'送达成功'
  226 + })
  227 + */
  228 + public function orderService()
  229 + {
  230 + $id = $this->request->post('id');
  231 + $rider_order = RiderOrder::get($id);
  232 + $ordermodel = new \app\api\model\Order();
  233 + $order = $ordermodel
  234 + ->where('id',$rider_order['order_id'])
  235 + ->find();
  236 + if ($order['rider_status'] == 20) $this->error('该订单已送达');
  237 + $order->rider_status = '20';
  238 + $order->isUpdate()->save();
  239 + $rider_order->status = '2';
  240 + $rider_order->sendtime = time();
  241 + $rider_order->isUpdate()->save();
  242 + $data = [
  243 + 'user_id' => $this->auth->id,
  244 + 'money' => $order->express_price,
  245 + 'memo' => '订单运费',
  246 + 'createtime' => time()
  247 + ];
  248 + Db::name('user_money_log')->insert($data);
  249 + $this->success('送达成功',$order);
  250 + }
  251 +
  252 +
  253 + /**
  254 + * @ApiTitle (骑手提现)
  255 + * @ApiMethod (POST)
  256 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  257 + * @ApiHeaders (name=money, type=integer, required=true, description="提现金额")
  258 + * @ApiReturn ({
  259 + 'code':'1',
  260 + 'msg':'送达成功'
  261 + })
  262 + */
  263 + public function withdraw()
  264 + {
  265 + $money = $this->request->post('money');
  266 + $user = $this->auth->getUser();
  267 + if ($user['money'] < $money) $this->error('可提现金额不足');
  268 + $user->setDec('money',$money);
  269 + $data = [
  270 + 'user_id' => $this->auth->id,
  271 + 'money' => $money,
  272 + 'memo' => '提现',
  273 + 'createtime' => time()
  274 + ];
  275 + Db::name('user_money_log')->insert($data);
  276 + $this->success('提现成功');
  277 + }
  278 +
  279 +
  280 + /**
  281 + * @ApiTitle (联系客服)
  282 + * @ApiMethod (POST)
  283 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  284 + * @ApiReturn ({
  285 + 'code':'1',
  286 + 'msg':'送达成功'
  287 + })
  288 + */
  289 + public function service()
  290 + {
  291 + $data = [
  292 + 'qrcode' => cdnurl(Config::get('site.work_qrcode'),true),
  293 + 'time' => Config::get('site.work_time'),
  294 + 'mobile' => Config::get('site.work_mobile')
  295 + ];
  296 + $this->success('客服信息',$data);
  297 + }
145 } 298 }
@@ -27,4 +27,9 @@ class Order extends Model @@ -27,4 +27,9 @@ class Order extends Model
27 { 27 {
28 return $this->hasMany('OrderGoods','order_id','id'); 28 return $this->hasMany('OrderGoods','order_id','id');
29 } 29 }
  30 +
  31 + public function address()
  32 + {
  33 + return $this->belongsTo('OrderAddress','id','order_id',[],'left')->setEagerlyType(0);
  34 + }
30 } 35 }
@@ -13,4 +13,13 @@ class OrderAddress extends Model @@ -13,4 +13,13 @@ class OrderAddress extends Model
13 protected $name = 'litestore_order_address'; 13 protected $name = 'litestore_order_address';
14 protected $createTime = 'createtime'; 14 protected $createTime = 'createtime';
15 protected $updateTime = ''; 15 protected $updateTime = '';
  16 + protected $append = [
  17 + 'mobile_hide'
  18 + ];
  19 +
  20 + public function getMobileHideAttr($value,$data)
  21 + {
  22 + $value = !empty($data['phone'])?str_replace(substr($data['phone'],3,4),'****',$data['phone']):'';
  23 + return $value;
  24 + }
16 } 25 }
@@ -334,47 +334,46 @@ class Api @@ -334,47 +334,46 @@ class Api
334 { 334 {
335 $time = time(); 335 $time = time();
336 $data = Db::name('timeslot')->column('time'); 336 $data = Db::name('timeslot')->column('time');
  337 + $array = [];
337 foreach ($data as $key => $value){ 338 foreach ($data as $key => $value){
338 - $data[$key] = strtotime($value); 339 + $array[] = strtotime($value);
339 } 340 }
340 - asort($data);  
341 - $count = count($data);  
342 - for ($i = 0,$j = 1;$i<$count-1,$j<$count;$i++,$j++){  
343 - if ($data[$i] <= $time && $data[$j] > $time){  
344 - $data[$i] = [  
345 - 'time'=>date('H:i',$data[$i]),  
346 - 'status' => 'begin'  
347 - ];  
348 - $data[$j] = [  
349 - 'time'=>date('H:i',$data[$j]),  
350 - 'status' => 'will'  
351 - ];  
352 - $i++;$j++;  
353 - }elseif($data[$i] < $time){  
354 - $data[$i] = [  
355 - 'time'=>date('H:i',$data[$i]),  
356 - 'status' => 'over'  
357 - ];  
358 - }elseif($i==0&&$data[$i] > $time){  
359 - $data[$i] = [  
360 - 'time'=>date('H:i',$data[$i]),  
361 - 'status' => 'will'  
362 - ]; 341 + asort($array);
  342 + $array = array_values($array);
  343 + $count = count($array);
  344 + for ($i = 0;$i<$count;$i++){
  345 + if (isset($array[$i+1])){
  346 + if ($array[$i] <= $time && $array[$i+1] > $time) {
  347 + $array[$i] = [
  348 + 'time' => date('H:i', $array[$i]),
  349 + 'status' => 'begin'
  350 + ];
  351 + $array[$i + 1] = [
  352 + 'time' => date('H:i', $array[$i + 1]),
  353 + 'status' => 'will'
  354 + ];
  355 + $i++;
  356 + }else{
  357 + if ($array[$i] < $time){
  358 + $array[$i] = [
  359 + 'time' => date('H:i', $array[$i]),
  360 + 'status' => 'over'
  361 + ];
  362 + }else{
  363 + $array[$i] = [
  364 + 'time' => date('H:i', $array[$i]),
  365 + 'status' => 'not'
  366 + ];
  367 + }
  368 + }
363 }else{ 369 }else{
364 - $data[$i] = [  
365 - 'time'=>date('H:i',$data[$i]),  
366 - 'status' => 'not'  
367 - ];  
368 - }  
369 - if ($count-$j == 1){  
370 - $data[$j] = [  
371 - 'time'=>date('H:i',$data[$j]),  
372 - 'status' => $data[$j] > $time ? 'not':'begin' 370 + $array[$i] = [
  371 + 'time'=>date('H:i',$array[$i]),
  372 + 'status' => $array[$i] > $time ? 'not':'begin'
373 ]; 373 ];
374 } 374 }
375 } 375 }
376 - var_dump($data);exit();  
377 - return array_values($data); 376 + return $array;
378 } 377 }
379 378
380 /** 379 /**
@@ -48,4 +48,8 @@ return array ( @@ -48,4 +48,8 @@ return array (
48 'invite_rule' => '啊实打实大苏打', 48 'invite_rule' => '啊实打实大苏打',
49 'secret' => '2d87e8e4f8e39ec44d4b0715107cf45b', 49 'secret' => '2d87e8e4f8e39ec44d4b0715107cf45b',
50 'appid' => 'wx3fb93805fc3f459d', 50 'appid' => 'wx3fb93805fc3f459d',
  51 + 'activity_image' => '',
  52 + 'work_time' => '',
  53 + 'work_qrcode' => '',
  54 + 'work_mobile' => '',
51 ); 55 );