Merge pull request 'dev' (#8) from dev into preview
Reviewed-on: https://gitea.lihaink.cn/mkm/logistics/pulls/8
This commit is contained in:
commit
696ac50780
@ -79,7 +79,8 @@ class ContractController extends BaseApiController
|
||||
'signing_timer' => $params['signing_timer'],
|
||||
'status' => $params['status'],
|
||||
'contract_url' => $params['contract_url'],
|
||||
'contract_evidence' => $params['contract_evidence']
|
||||
'contract_evidence' => $params['contract_evidence'],
|
||||
'update_time' => $params['update_time']
|
||||
]);
|
||||
if($contract['type'] == 0){
|
||||
foreach($cars as $v){
|
||||
|
@ -15,6 +15,8 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\logic\LogisticsLogic;
|
||||
use app\common\model\logistics\Logistics;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 物流管理
|
||||
@ -35,7 +37,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param int $page_num 页码
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierLogisticsList(): \think\response\Json
|
||||
public function courierLogisticsList(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->get(['user_id','user_type','status','page_size','page_num','keywords']);
|
||||
@ -54,7 +56,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierLogisticsDetail(): \think\response\Json
|
||||
public function courierLogisticsDetail(): Json
|
||||
{
|
||||
//获取参数
|
||||
$logistics_id = $this->request->get('logistics_id');
|
||||
@ -71,7 +73,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param string $order_sn 订单编号
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function logisticsCreate(): \think\response\Json
|
||||
public function logisticsCreate(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['order_id','order_sn']);
|
||||
@ -89,7 +91,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierTakeGoods(): \think\response\Json
|
||||
public function courierTakeGoods(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['logistics_id','order_id','order_sn']);
|
||||
@ -107,7 +109,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierCompleteDelivery(): \think\response\Json
|
||||
public function courierCompleteDelivery(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['logistics_id','take_code']);
|
||||
@ -125,7 +127,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function userCancelOrder(): \think\response\Json
|
||||
public function userCancelOrder(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['order_id','order_sn']);
|
||||
@ -143,7 +145,7 @@ class LogisticsController extends BaseApiController
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function userLogisticsDetail(): \think\response\Json
|
||||
public function userLogisticsDetail(): Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->get(['order_id','order_sn']);
|
||||
@ -154,7 +156,7 @@ class LogisticsController extends BaseApiController
|
||||
}
|
||||
|
||||
//获取配送员
|
||||
public function hasCourier(): \think\response\Json {
|
||||
public function hasCourier(): Json {
|
||||
//获取参数
|
||||
$param = $this->request->get('user_address_code');
|
||||
if(empty($param)) {
|
||||
@ -168,5 +170,25 @@ class LogisticsController extends BaseApiController
|
||||
return $this->fail('无配送员');
|
||||
}
|
||||
}
|
||||
|
||||
//获取配送员信息
|
||||
public function courierData(): Json
|
||||
{
|
||||
$params = $this->request->get(['order_sn']);
|
||||
if(empty($params['order_sn'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$data = Logistics::where('order_sn',$params['order_sn'])->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return $this->fail('订单信息错误');
|
||||
}
|
||||
$result = [
|
||||
'courier_id' => $data['courier_id'],
|
||||
'courier_name' => $data['courier_name'],
|
||||
'courier_phone' => $data['courier_phone'],
|
||||
'courier_company' => $data['courier_company'],
|
||||
];
|
||||
return $this->success('请求成功',$result);
|
||||
}
|
||||
|
||||
}
|
@ -54,7 +54,7 @@ class LogisticsLogic extends BaseLogic
|
||||
}
|
||||
$logistics = Logistics::where([$user])
|
||||
->where([$status])
|
||||
->where('(order_sn LIKE "%'.$params['keywords'].'%" OR shop_phone LIKE "%'.$params['keywords'].'%" OR shop_name LIKE "%'.$params['keywords'].'%" OR receiver_phone LIKE "%'.$params['keywords'].'%" OR receiver_name LIKE "%'.$params['keywords'].'%")')
|
||||
->where('(order_sn LIKE "%'.$params['keywords'].'%" OR shop_phone LIKE "%'.$params['keywords'].'%" OR shop_name LIKE "%'.$params['keywords'].'%" OR shop_user LIKE "%'.$params['keywords'].'%" OR receiver_phone LIKE "%'.$params['keywords'].'%" OR receiver_name LIKE "%'.$params['keywords'].'%")')
|
||||
->order('update_time desc')
|
||||
->paginate([
|
||||
'list_rows'=> !empty($params['page_size'])? $params['page_size'] : 6,
|
||||
@ -67,6 +67,7 @@ class LogisticsLogic extends BaseLogic
|
||||
$pro_item['cart_info'] = json_decode($pro_item['cart_info'], true);
|
||||
$pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name'];
|
||||
$pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name'];
|
||||
$pro_item['goods_pic'] = $pro_item['cart_info']['product']['image'];
|
||||
$product_count += $pro_item['product_num'];
|
||||
unset($pro_item['cart_info']);
|
||||
return $pro_item;
|
||||
@ -85,14 +86,26 @@ class LogisticsLogic extends BaseLogic
|
||||
*/
|
||||
public static function cDetail($id):array {
|
||||
//获取物流信息
|
||||
$logistics = Logistics::field('id,order_id,order_sn,shop_name,shop_user,shop_phone,shop_address,shop_long,shop_lat,receiver_name,receiver_phone,receiver_address,status,create_time')
|
||||
$logistics = Logistics::field('id,order_id,order_sn,shop_name,shop_user,shop_phone,shop_address,shop_long,shop_lat,receiver_name,receiver_phone,receiver_address,status,create_time,qh_time,ps_time,qx_time')
|
||||
->where('id', $id)->find();
|
||||
//查找订单信息
|
||||
if(empty($logistics)){
|
||||
return [
|
||||
'logistics' => [],
|
||||
'product' => [],
|
||||
'product_count' => 0,
|
||||
'record' => [],
|
||||
];
|
||||
}
|
||||
$order = Order::alias('s')->where('order_id', $logistics['order_id'])->where('order_sn', $logistics['order_sn'])->find();
|
||||
$logistics['mark'] = !empty($order) ? $order['mark'] : '';
|
||||
//获取商品信息
|
||||
$product_count = 0;
|
||||
$product = Product::field('product_num,cart_info')->where('order_id', $logistics['order_id'])->select()->each(function($pro_item) use(&$product_count){
|
||||
$pro_item['cart_info'] = json_decode($pro_item['cart_info'], true);
|
||||
$pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name'];
|
||||
$pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name'];
|
||||
$pro_item['goods_pic'] = $pro_item['cart_info']['product']['image'];
|
||||
$product_count += $pro_item['product_num'];
|
||||
unset($pro_item['cart_info']);
|
||||
return $pro_item;
|
||||
@ -230,13 +243,21 @@ class LogisticsLogic extends BaseLogic
|
||||
return ['code'=>0, 'msg'=>$e->getMessage()];
|
||||
}
|
||||
//推送消息
|
||||
$register_id = Courier::field('register_id')->where('id',$courier['user_id'])->find();
|
||||
if($register_id && !empty($register_id['register_id'])){
|
||||
$push_result = push_message($register_id['register_id'],'您有一条新的配送任务,请尽快处理!!');
|
||||
if($push_result['code'] == 0) {
|
||||
Log::write('["极光推送:"]'.$push_result['msg'],'error');
|
||||
}
|
||||
}
|
||||
$register_id = Courier::field('register_id,ytj_register_id')->where('id',$courier['user_id'])->findOrEmpty();
|
||||
if(!$register_id->isEmpty()){
|
||||
if(!empty($register_id['ytj_register_id'])){
|
||||
$push_result2 = push_message2($register_id['ytj_register_id'],'您有一条新的配送任务,请尽快处理!!');
|
||||
if($push_result2['code'] == 0) {
|
||||
Log::write('["极光推送2:"]'.$push_result2['msg'],'error');
|
||||
}
|
||||
}
|
||||
if(!empty($register_id['register_id'])){
|
||||
$push_result1 = push_message($register_id['register_id'],'您有一条新的配送任务,请尽快处理!!');
|
||||
if($push_result1['code'] == 0) {
|
||||
Log::write('["极光推送1:"]'.$push_result1['msg'],'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['code'=>1, 'msg'=>'操作成功','data'=>['nickname'=>$courier['master_name'],'phone'=>$courier['master_phone']]];
|
||||
}
|
||||
|
||||
|
@ -341,6 +341,25 @@ function push_message($reg_id,$message){
|
||||
}
|
||||
}
|
||||
|
||||
function push_message2($reg_id,$message){
|
||||
//获取配置信息
|
||||
$jpush_config = config('app.jpush2');
|
||||
$app_key= $jpush_config['app_key']; //这是app密钥,填你自己的
|
||||
$master_secret= $jpush_config['master_secret']; //这也是密钥,填你自己的
|
||||
//实例化
|
||||
$client = new Client($app_key,$master_secret);
|
||||
$pusher = $client->push();
|
||||
$pusher->setPlatform('all');
|
||||
$pusher->addRegistrationId($reg_id);
|
||||
$pusher->setNotificationAlert($message);
|
||||
try {
|
||||
$res = $pusher->send();
|
||||
return ['code'=>1,'msg'=>'','data'=>$res];
|
||||
} catch (\JPush\Exceptions\JPushException $e) {
|
||||
return ['code'=>0,'msg'=>$e->getMessage(),'data'=>[]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 校验日期格式是否正确
|
||||
|
191
app/common/controller/LogisticController.php
Normal file
191
app/common/controller/LogisticController.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\api\logic\LogisticsLogic;
|
||||
use app\common\model\logistics\Logistics;
|
||||
use app\common\model\logistics\LogisticsRecord;
|
||||
use app\common\model\logistics\Product;
|
||||
use think\facade\Log;
|
||||
|
||||
class LogisticController extends BaseLikeAdminController
|
||||
{
|
||||
public function lists(): \think\response\Json
|
||||
{
|
||||
$params = $this->request->post(['order_sn','shop_name','user_name','courier_name','status','page_no','page_size']);
|
||||
if(empty($params['page_no']) || empty($params['page_size'])){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
$where = [];
|
||||
foreach($params as $k => $v) {
|
||||
if($k=='page_no' || $k=='page_size'){
|
||||
continue;
|
||||
}
|
||||
if($k != 'status'){
|
||||
$where[] = [$k,'like','%'.$v.'%'];
|
||||
}else{
|
||||
if($v==2){
|
||||
$where[] = [$k,'in','2,3'];
|
||||
}else{
|
||||
$where[] = [$k,'=',$v];
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = Logistics::field(['id','order_id','order_sn','shop_name','shop_phone','receiver_name','receiver_phone','receiver_address','courier_name','courier_company','status','qh_time','ps_time','qx_time','create_time'])
|
||||
->where($where)
|
||||
->order(['id' => 'desc'])
|
||||
->page($params['page_no'],$params['page_size'])
|
||||
->select()
|
||||
->each(function ($item){
|
||||
$item['status_name'] = $item->status_name;
|
||||
$product_count = 0;
|
||||
//获取产品信息
|
||||
$item['products'] = Product::field('product_num,cart_info')->where('order_id', $item['order_id'])->select()->each(function($pro_item) use(&$product_count){
|
||||
$pro_item['cart_info'] = json_decode($pro_item['cart_info'], true);
|
||||
$pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name'];
|
||||
$pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name'];
|
||||
$product_count += $pro_item['product_num'];
|
||||
unset($pro_item['cart_info']);
|
||||
return $pro_item;
|
||||
});
|
||||
$item['product_count'] = $product_count;
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
$count = Logistics::field(['id'])->where($where)->count();
|
||||
$result = [
|
||||
'lists'=>$data,
|
||||
'count' => $count,
|
||||
'page_no' => $params['page_no'],
|
||||
'page_size' => $params['page_size']
|
||||
];
|
||||
return $this->success('请求成功',$result);
|
||||
}
|
||||
|
||||
public function detail(): \think\response\Json
|
||||
{
|
||||
$params = $this->request->post(['id']);
|
||||
if(empty($params['id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$logistics = Logistics::findOrEmpty($params['id']);
|
||||
$logistics['status_name'] = $logistics->status_name;
|
||||
//获取商品信息
|
||||
$product_count = 0;
|
||||
$product = Product::field('product_num,cart_info')->where('order_id', $logistics['order_id'])->select()->each(function($pro_item) use(&$product_count){
|
||||
$pro_item['cart_info'] = json_decode($pro_item['cart_info'], true);
|
||||
$pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name'];
|
||||
$pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name'];
|
||||
$pro_item['goods_pic'] = $pro_item['cart_info']['product']['image'];
|
||||
$pro_item['goods_price'] = $pro_item['cart_info']['product']['price'];
|
||||
$pro_item['goods_sku'] = $pro_item['cart_info']['productAttr']['sku'];
|
||||
$pro_item['goods_total_price'] = $pro_item['cart_info']['product']['price'] * $pro_item['product_num'];
|
||||
$product_count += $pro_item['product_num'];
|
||||
unset($pro_item['cart_info']);
|
||||
return $pro_item;
|
||||
})->toArray();
|
||||
$logistics['product'] = $product;
|
||||
//获取物流记录
|
||||
$records = LogisticsRecord::field('type,user_name,content,create_time')
|
||||
->where('lst_id', $logistics['id'])->order('create_time asc')->select()->each(function($red_item){
|
||||
switch ($red_item['type']) {
|
||||
case 1:
|
||||
$red_item['content'] = '用户'.$red_item['user_name'].$red_item['content'];
|
||||
break;
|
||||
case 2:
|
||||
$red_item['content'] = '配送员'.$red_item['user_name'].$red_item['content'];
|
||||
break;
|
||||
case 3:
|
||||
$red_item['content'] = '平台'.$red_item['user_name'].$red_item['content'];
|
||||
break;
|
||||
default:
|
||||
$red_item['content'] = '未知';
|
||||
}
|
||||
unset($red_item['type'], $red_item['user_name']);
|
||||
})->toArray();
|
||||
$logistics['records'] = $records;
|
||||
//返回数据
|
||||
return $this->success('请求成功',$logistics->toArray());
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取配送员物流信息列表
|
||||
* @method get
|
||||
* @param int $courier_id 配送员id
|
||||
* @param int $status 物流状态
|
||||
* @param int $page_size 每页数量
|
||||
* @param int $page_num 页码
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierLogisticsList(): \think\response\Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['user_id','user_type','status','page_size','page_num','keywords']);
|
||||
//验证参数
|
||||
if(empty($params['user_id'])) return $this->fail('参数错误');
|
||||
if(!isset($params['user_type'])) return $this->fail('参数错误');
|
||||
if(empty($params['keywords'])) $params['keywords'] = '';
|
||||
//返回数据
|
||||
return $this->data(LogisticsLogic::list($params));
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取物流信息详情
|
||||
* @method get
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierLogisticsDetail(): \think\response\Json
|
||||
{
|
||||
//获取参数
|
||||
$logistics_id = $this->request->post('logistics_id');
|
||||
//验证参数
|
||||
if(empty($logistics_id)) return $this->fail('参数错误');
|
||||
//返回数据
|
||||
return $this->data(LogisticsLogic::cDetail($logistics_id));
|
||||
}
|
||||
|
||||
/*
|
||||
* 配送员提取商品
|
||||
* @method post
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierTakeGoods(): \think\response\Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['logistics_id','order_id','order_sn']);
|
||||
//验证参数
|
||||
if(empty($params['logistics_id']) || empty($params['order_id']) || empty($params['order_sn'])) return $this->fail('参数错误');
|
||||
//提取商品
|
||||
$result = LogisticsLogic::takeGoods($params);
|
||||
//返回数据
|
||||
return $result['code'] ==1 ? $this->success('提取成功') : $this->fail($result['msg']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 配送员完成配送
|
||||
* @method post
|
||||
* @param int $logistics_id 物流id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function courierCompleteDelivery(): \think\response\Json
|
||||
{
|
||||
//获取参数
|
||||
$params = $this->request->post(['logistics_id','take_code']);
|
||||
//验证参数
|
||||
if(empty($params['logistics_id']) || empty($params['take_code'])) return $this->fail('参数错误');
|
||||
//完成配送
|
||||
$result = LogisticsLogic::doneDelivery($params);
|
||||
//返回数据
|
||||
return $result['code'] ==1 ? $this->success('配送完成') : $this->fail($result['msg']);
|
||||
}
|
||||
|
||||
// public function test() {
|
||||
// $push_result = push_message2('1507bfd3f6c212e2012','您有一条新的配送任务,请尽快处理!!');
|
||||
// if($push_result['code'] == 0) {
|
||||
// Log::write('["极光推送:"]'.$push_result['msg'],'error');
|
||||
// }else{
|
||||
// return $this->success('ok',$push_result);
|
||||
// }
|
||||
// }
|
||||
}
|
@ -29,9 +29,13 @@ return [
|
||||
'error_message' => '页面错误!请稍后再试~',
|
||||
// 显示错误信息
|
||||
'show_error_msg' => false,
|
||||
// 机关推送
|
||||
// 极光推送
|
||||
'jpush' => [
|
||||
'app_key' => '5ced5ec5fa7bb86302944f0f',
|
||||
'master_secret' => 'd85135e7d8470c90b476e535',
|
||||
],
|
||||
'jpush2' => [
|
||||
'app_key' => 'ef20394fbd9b59ead68f53b3',
|
||||
'master_secret' => 'cb588b0d210df80b3659c543',
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user