作者 李忠强

更新

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
use think\Db;
/**
* 首页活动
*/
class Activity extends Api
{
protected $noNeedRight = ['*'];
protected $noNeedLogin = ['*'];
/**
* @ApiTitle (活动名称列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="活动ID")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':
"list": {
"total": 4, 总条数
"per_page": 10,每页数量
"current_page": 1,当前页
"last_page": 1,最后一页
"data": [
{
"goods_id": 21,
"goods_name": "小米Mix3",
"price": "100.00",
"line_price": "1000.00",划线价
"image_text": "图片路径"
}
]
},
"timeslot": "秒杀时间段"
"image": "广告图"
})
*/
public function activity()
{
$list = Db::name('activity')->select();
$this->success('活动商品列表',['list'=>$list]);
}
/**
* @ApiTitle (活动商品列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="活动ID")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':
"list": {
"total": 4, 总条数
"per_page": 10,每页数量
"current_page": 1,当前页
"last_page": 1,最后一页
"data": [
{
"goods_id": 21,
"goods_name": "小米Mix3",
"price": "100.00",
"line_price": "1000.00",划线价
"image_text": "图片路径"
}
]
},
"timeslot": "秒杀时间段"
{
"time": "16:41",
"status": "not" not 未开始 will即将开始 begin 抢购中 over 已结束
},
{
"time": "17:24",
"status": "not"
},
"image": "广告图"
})
*/
public function listGoods()
{
$id = $this->request->post('id');
$page = $this->request->post('page',1);
if (!is_numeric($page) || !is_numeric($id)) $this->error('参数不合法');
$model = new \app\api\model\Goods();
$list = $model
->where('is_delete','0')
->where('goods_status','10')
->where('activity_id',$id)
->field('goods_id,goods_name,image')
->paginate(10,false,['page'=>$page])
->each(function ($item,$key){
$goods_spec = Db::name('litestore_goods_spec')
->where('goods_id',$item['goods_id'])
->find();
$item['price'] = $goods_spec['goods_price'];
$item['line_price'] = $goods_spec['line_price'];
});
$timeslot = $this->timeplot();
$image = cdnurl(Config::get('site.activity_image'),true);
$this->success('活动商品列表',['list'=>$list,'timeslot'=>$timeslot,'image'=>$image]);
}
}
\ No newline at end of file
... ...
... ... @@ -184,7 +184,7 @@ class Goods extends Api
}
$model = new GoodsComment();
$goods = [];
$goods['comment_number'] = $model->where('status','normal')->count();
$goods['comment_number'] = $model->where('goods_id',$goods_id)->where('status','normal')->count();
$goods['comment'] = $model
->with(['user'])
->where('goods_id',$goods_id)
... ...
... ... @@ -469,4 +469,108 @@ class Order extends Api
$this->success('支付信息',$result);
}
/**
* @ApiTitle (确认收货)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="订单ID")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function takeover()
{
$order_id = $this->request->post('id');
if (!is_numeric($order_id)) $this->error('参数不合法');
$model = new \app\api\model\Order();
$order = $model::get($order_id);
if (!$order) $this->error('订单不存在');
if ($order['receipt_status'] == 20) $this->error('订单已收货,请勿重复提交');
$order->receipt_status = '20';
$order->isUpdate()->save();
$this->success('收货成功');
}
/**
* @ApiTitle (提醒发货)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="订单ID")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function remind()
{
$order_id = $this->request->post('id');
if (!is_numeric($order_id)) $this->error('参数不合法');
$model = new \app\api\model\Order();
$model->where('id',$order_id)->isUpdate()->save(['remind_status'=>'20']);
$this->success('提醒成功');
}
/**
* @ApiTitle (取消订单)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="订单ID")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function cancelOrder()
{
$order_id = $this->request->post('id');
if (!is_numeric($order_id)) $this->error('参数不合法');
$model = new \app\api\model\Order();
$model->where('id',$order_id)->isUpdate()->save(['order_status'=>'20']);
$this->success('取消成功');
}
/**
* @ApiTitle (评价订单)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="订单ID")
* @ApiParams (name="score", type="integer", required=true, description="评价分数")
* @ApiParams (name="comment", type="string", required=true, description="评价内容")
* @ApiParams (name="images", type="string", required=true, description="评价图片逗号隔开")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
})
*/
public function commentOrder()
{
$order_id = $this->request->post('id');
$score = $this->request->post('score');
$comment = $this->request->post('comment');
$images = $this->request->post('images');
if (!is_numeric($order_id)) $this->error('订单id参数不合法');
if (!is_numeric($score) || $score>5 || $score<1) $this->error('评价分数不合法');
if (!$comment) $this->error('请填写评价内容');
if (!$comment) $this->error('请填写评价内容');
if ($images){
$arr = explode(',',$images);
if (count($arr) > 3) $this->error('请上传最多3张评价图片');
}
$model = new \app\api\model\Order();
$model->where('id',$order_id)->isUpdate()->save(['order_status'=>'30']);
// $data = [
// 'user_id' => $this->auth->id,
// 'goods_id' => $
// ]
$this->success('取消成功');
}
}
\ No newline at end of file
... ...
... ... @@ -6,6 +6,8 @@ namespace app\api\controller;
use app\api\model\RiderOrder;
use app\common\controller\Api;
use think\Config;
use think\Db;
/**
* 骑手
... ... @@ -13,7 +15,7 @@ use app\common\controller\Api;
class Rider extends Api
{
protected $noNeedRight = ['*'];
// protected $noNeedLogin = ['*'];
protected $noNeedLogin = ['*'];
/**
* @ApiTitle (骑手订单页)
... ... @@ -142,4 +144,155 @@ class Rider extends Api
$data['all_order'] = $allcount;
$this->success('骑手个人页',$data);
}
/**
* @ApiTitle (骑手订单详情)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiHeaders (name=id, type=integer, required=true, description="骑手订单id")
* @ApiHeaders (name=lat, type=float, required=true, description="纬度")
* @ApiHeaders (name=lng, type=float, required=true, description="经度")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':
"id": 7,
"order_no": "LQ-16420622494781", 订单编号
"distance": 111.3195, 距离
"address": {
"id": 1,
"name": "1", 姓名
"phone": "13549059988",
"detail": "阿松大1", 门牌号
"address": "阿松大", 地址
"order_id": 7,
"user_id": 1,
"lat": "116.397128",
"lng": "39.916527",
"createtime": 0,
"province_id": 1,
"city_id": 2,
"region_id": 3,
"mobile_hide": "135****9988" 电话号码
},
"goods": [
{
"goods_name": "Mate 20 华为 HUAWEI ",
"goods_attr": "极光色 8GB+128GB",
"image_text": "http://temporaryfood.qiniu.broing.cn123132"
},
{
"goods_name": "MacBook Pro 13寸",
"goods_attr": "天空灰",
"image_text": "http://temporaryfood.qiniu.broing.cn123132"
}
],
"createtime_text": ""
})
*/
public function orderDetail()
{
$id = $this->request->post('id');
$lat = $this->request->post('lat');
$lng = $this->request->post('lng');
$rider_order = RiderOrder::get($id);
$ordermodel = new \app\api\model\Order();
$order = $ordermodel
->with(['address','goods'])
->where('fa_litestore_order.id',$rider_order['order_id'])
->find();
$order->visible(['order_no','address','goods','id','distance']);
foreach ($order->getRelation('goods') as $key => $value){
$value->visible(['goods_name','goods_attr']);
}
$lat1 = $order['address']['lat'];
$lng1 = $order['address']['lng'];
$lat2 = $lat;
$lng2 = $lng;
$order['distance'] = getDistance($lat1,$lng1,$lat2,$lng2);
$this->success('骑手个人页',$order);
}
/**
* @ApiTitle (骑手已送达)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiHeaders (name=id, type=integer, required=true, description="骑手订单id")
* @ApiReturn ({
'code':'1',
'msg':'送达成功'
})
*/
public function orderService()
{
$id = $this->request->post('id');
$rider_order = RiderOrder::get($id);
$ordermodel = new \app\api\model\Order();
$order = $ordermodel
->where('id',$rider_order['order_id'])
->find();
if ($order['rider_status'] == 20) $this->error('该订单已送达');
$order->rider_status = '20';
$order->isUpdate()->save();
$rider_order->status = '2';
$rider_order->sendtime = time();
$rider_order->isUpdate()->save();
$data = [
'user_id' => $this->auth->id,
'money' => $order->express_price,
'memo' => '订单运费',
'createtime' => time()
];
Db::name('user_money_log')->insert($data);
$this->success('送达成功',$order);
}
/**
* @ApiTitle (骑手提现)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiHeaders (name=money, type=integer, required=true, description="提现金额")
* @ApiReturn ({
'code':'1',
'msg':'送达成功'
})
*/
public function withdraw()
{
$money = $this->request->post('money');
$user = $this->auth->getUser();
if ($user['money'] < $money) $this->error('可提现金额不足');
$user->setDec('money',$money);
$data = [
'user_id' => $this->auth->id,
'money' => $money,
'memo' => '提现',
'createtime' => time()
];
Db::name('user_money_log')->insert($data);
$this->success('提现成功');
}
/**
* @ApiTitle (联系客服)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
'code':'1',
'msg':'送达成功'
})
*/
public function service()
{
$data = [
'qrcode' => cdnurl(Config::get('site.work_qrcode'),true),
'time' => Config::get('site.work_time'),
'mobile' => Config::get('site.work_mobile')
];
$this->success('客服信息',$data);
}
}
\ No newline at end of file
... ...
... ... @@ -27,4 +27,9 @@ class Order extends Model
{
return $this->hasMany('OrderGoods','order_id','id');
}
public function address()
{
return $this->belongsTo('OrderAddress','id','order_id',[],'left')->setEagerlyType(0);
}
}
\ No newline at end of file
... ...
... ... @@ -13,4 +13,13 @@ class OrderAddress extends Model
protected $name = 'litestore_order_address';
protected $createTime = 'createtime';
protected $updateTime = '';
protected $append = [
'mobile_hide'
];
public function getMobileHideAttr($value,$data)
{
$value = !empty($data['phone'])?str_replace(substr($data['phone'],3,4),'****',$data['phone']):'';
return $value;
}
}
\ No newline at end of file
... ...
... ... @@ -334,47 +334,46 @@ class Api
{
$time = time();
$data = Db::name('timeslot')->column('time');
$array = [];
foreach ($data as $key => $value){
$data[$key] = strtotime($value);
}
asort($data);
$count = count($data);
for ($i = 0,$j = 1;$i<$count-1,$j<$count;$i++,$j++){
if ($data[$i] <= $time && $data[$j] > $time){
$data[$i] = [
'time'=>date('H:i',$data[$i]),
$array[] = strtotime($value);
}
asort($array);
$array = array_values($array);
$count = count($array);
for ($i = 0;$i<$count;$i++){
if (isset($array[$i+1])){
if ($array[$i] <= $time && $array[$i+1] > $time) {
$array[$i] = [
'time' => date('H:i', $array[$i]),
'status' => 'begin'
];
$data[$j] = [
'time'=>date('H:i',$data[$j]),
$array[$i + 1] = [
'time' => date('H:i', $array[$i + 1]),
'status' => 'will'
];
$i++;$j++;
}elseif($data[$i] < $time){
$data[$i] = [
'time'=>date('H:i',$data[$i]),
$i++;
}else{
if ($array[$i] < $time){
$array[$i] = [
'time' => date('H:i', $array[$i]),
'status' => 'over'
];
}elseif($i==0&&$data[$i] > $time){
$data[$i] = [
'time'=>date('H:i',$data[$i]),
'status' => 'will'
];
}else{
$data[$i] = [
'time'=>date('H:i',$data[$i]),
$array[$i] = [
'time' => date('H:i', $array[$i]),
'status' => 'not'
];
}
if ($count-$j == 1){
$data[$j] = [
'time'=>date('H:i',$data[$j]),
'status' => $data[$j] > $time ? 'not':'begin'
}
}else{
$array[$i] = [
'time'=>date('H:i',$array[$i]),
'status' => $array[$i] > $time ? 'not':'begin'
];
}
}
var_dump($data);exit();
return array_values($data);
return $array;
}
/**
... ...
... ... @@ -48,4 +48,8 @@ return array (
'invite_rule' => '啊实打实大苏打',
'secret' => '2d87e8e4f8e39ec44d4b0715107cf45b',
'appid' => 'wx3fb93805fc3f459d',
'activity_image' => '',
'work_time' => '',
'work_qrcode' => '',
'work_mobile' => '',
);
... ...