Browse Source

Merge branch 'horseman'

master
Lemon 5 years ago
parent
commit
92cd933126
  1. 10
      app/Constants/v3/ErrorCode.php
  2. 10
      app/Constants/v3/SsdbKeys.php
  3. 6
      app/Controller/v3/GoodsController.php
  4. 8
      app/Controller/v3/HomeController.php
  5. 90
      app/Controller/v3/HorsemanController.php
  6. 10
      app/Controller/v3/NotifyController.php
  7. 26
      app/Controller/v3/OrderOnlineController.php
  8. 2
      app/Controller/v3/SearchController.php
  9. 5
      app/Controller/v3/UserAddressController.php
  10. 22
      app/Model/v3/Employees.php
  11. 6
      app/Model/v3/Goods.php
  12. 17
      app/Model/v3/OrderMain.php
  13. 33
      app/Request/v3/EmployeesRequest.php
  14. 33
      app/Request/v3/HorsemanOrderRequest.php
  15. 28
      app/Service/v3/Implementations/DistributionPriceService.php
  16. 10
      app/Service/v3/Implementations/FeiePrintService.php
  17. 48
      app/Service/v3/Implementations/HelperService.php
  18. 95
      app/Service/v3/Implementations/HorsemanService.php
  19. 2
      app/Service/v3/Implementations/OrderListService.php
  20. 33
      app/Service/v3/Implementations/OrderOnlineService.php
  21. 18
      app/Service/v3/Implementations/OrderStatisticsService.php
  22. 13
      app/Service/v3/Implementations/SearchService.php
  23. 3
      app/Service/v3/Implementations/StoreService.php
  24. 11
      app/Service/v3/Implementations/TabsService.php
  25. 10
      app/Service/v3/Implementations/UserAddressService.php
  26. 36
      app/Service/v3/Implementations/UserCenterBlockService.php
  27. 9
      app/Service/v3/Implementations/UserInfoService.php
  28. 2
      app/Service/v3/Interfaces/DistributionPriceServiceInterface.php
  29. 16
      app/Service/v3/Interfaces/HorsemanServiceInterface.php
  30. 9
      app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
  31. 2
      app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php
  32. 2
      app/Service/v3/Interfaces/UserInfoServiceInterface.php
  33. 1
      config/autoload/dependencies.php
  34. 2
      config/config.php
  35. 7
      config/routes.php

10
app/Constants/v3/ErrorCode.php

@ -406,4 +406,14 @@ class ErrorCode extends AbstractConstants
* @Message("token解析失败") * @Message("token解析失败")
*/ */
const TOKEN_NOT_EXISTS = 1353; const TOKEN_NOT_EXISTS = 1353;
/************************************/
/* 骑手相关 1451-1500 */
/************************************/
/**
* 获取骑手坐标失败
* @Message("获取骑手坐标失败")
*/
const HORSEMAN_COORDINATE_FAIL = 1451;
} }

10
app/Constants/v3/SsdbKeys.php

@ -80,4 +80,14 @@ class SsdbKeys extends AbstractConstants
*/ */
const PARAMS_TOKEN = 'params_token_v3_'; const PARAMS_TOKEN = 'params_token_v3_';
/**
* @Message("骑手坐标")
*/
const HORSEMAN_COORDINATE = 'horseman_coordinate_';
/**
* @Message("市场当日线上订单数量统计")
*/
const TODAY_SALES_FOR_MARKET = 'today_sales_for_market_';
} }

6
app/Controller/v3/GoodsController.php

@ -2,7 +2,9 @@
namespace App\Controller\v3; namespace App\Controller\v3;
use App\Constants\v3\ErrorCode;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Exception\ErrorCodeException;
use App\Model\v3\Category; use App\Model\v3\Category;
use App\Model\v3\GoodsCategory; use App\Model\v3\GoodsCategory;
use App\Request\v3\GoodsEditorRequest; use App\Request\v3\GoodsEditorRequest;
@ -62,6 +64,10 @@ class GoodsController extends BaseController
$res['banner'] = $this->goodsService->getBanner($goodsId); $res['banner'] = $this->goodsService->getBanner($goodsId);
} }
//搜索不到商品
if(is_null($res['detail']['id'])){
throw new ErrorCodeException(ErrorCode::GOODS_ON_SALE_NO);
}
//如果没有banner数据,使用商品cover图 //如果没有banner数据,使用商品cover图
if(count($res['banner']) == 0){ if(count($res['banner']) == 0){
// $res['banner'] = [$res['detail']['cover_img']]; // $res['banner'] = [$res['detail']['cover_img']];

8
app/Controller/v3/HomeController.php

@ -160,10 +160,10 @@ class HomeController extends BaseController
$params = $request->validated(); $params = $request->validated();
$data['user'] = $this->userInfoService->detail($params['user_id']); $data['user'] = $this->userInfoService->detail($params['user_id']);
$store_info = $this->userInfoService->getStoreByUID($params['user_id']); $store_info = $this->userInfoService->getStoreByUID($params['user_id']);
$sp_info = $this->userInfoService->getServicePersonnelByUID($params['user_id']);
$employees = $this->userInfoService->getEmployeesByUID($params['user_id']);
$data['user']['store_info'] = $store_info; $data['user']['store_info'] = $store_info;
$data['user']['sp_info'] = $sp_info;
$data['user']['sp_info'] = $employees;
$roles = []; $roles = [];
@ -177,12 +177,12 @@ class HomeController extends BaseController
]; ];
} }
if($sp_info){
if($employees){
$roles[] = [ $roles[] = [
'key'=>'sp', 'key'=>'sp',
'title'=>'服务', 'title'=>'服务',
'color'=>'#0091FF', 'color'=>'#0091FF',
'data'=>$sp_info,
'data'=>$employees,
]; ];
} }

90
app/Controller/v3/HorsemanController.php

@ -0,0 +1,90 @@
<?php
namespace App\Controller\v3;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel;
use App\Controller\BaseController;
use App\Exception\ErrorCodeException;
use App\Model\v3\OrderMain;
use App\Service\v3\Interfaces\HorsemanServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Request\v3\EmployeesRequest;
use App\Request\v3\HorsemanOrderRequest;
class HorsemanController extends BaseController
{
/**
* @Inject
* @var HorsemanServiceInterface
*/
protected $horsemanService;
/**
* @Inject
* @var OrderOnlineServiceInterface
*/
protected $orderOnlineService;
/**
* @Inject
* @var SeparateAccountsServiceInterface
*/
protected $separateAccountsService;
public function getOrderList(EmployeesRequest $request)
{
$employeesId = $this->request->input('employees_id', -1);
$page = $this->request->input('page',0);
$pagesize = $this->request->input('pagesize',0);
$orderMainList = $this->horsemanService->getOrderList($employeesId,$page, $pagesize);
return $this->success($orderMainList);
}
public function getOrderInfo(HorsemanOrderRequest $request)
{
$globalOrderId = $this->request->input('global_order_id', -1);
$orderMain = $this->orderOnlineService->getOrderInfo($globalOrderId);
return $this->success(['order' => $orderMain]);
}
public function setHorsemanCoordinate(EmployeesRequest $request)
{
$employeesId = $this->request->input('employees_id', -1);
$coordinate = $this->request->input('coordinate', -1);
return $this->success($this->horsemanService->setHorsemanCoordinate($employeesId,$coordinate));
}
public function getHorsemanCoordinate(EmployeesRequest $request)
{
$employeesId = $this->request->input('employees_id', -1);
$coordinate = $this->horsemanService->getHorsemanCoordinate($employeesId);
return $this->success(['coordinate' => $coordinate]);
}
public function getOrderCoordinate()
{
$globalOrderId = $this->request->input('global_order_id', -1);
return $this->success($this->horsemanService->getOrderCoordinate($globalOrderId));
}
public function orderComplete(HorsemanOrderRequest $request)
{
$globalOrderId = $this->request->input('global_order_id', -1);
$userId = OrderMain::query()->where('global_order_id',$globalOrderId)->value('user_id');
Db::beginTransaction();
try {
$this->orderOnlineService->doComplete($globalOrderId, $userId);
$this->separateAccountsService->orderOnlineCompleted($globalOrderId, $userId);
Db::commit();
return $this->success(true);
} catch (\Exception $e) {
Db::rollBack();
$this->log->event(LogLabel::ORDER_COMPLETE_LOG, ['exception' => $e->getMessage()]);
throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
}
}
}

10
app/Controller/v3/NotifyController.php

@ -23,6 +23,7 @@ use App\Service\v3\Interfaces\MiniprogramServiceInterface;
use App\Service\v3\Interfaces\MqttServiceInterface; use App\Service\v3\Interfaces\MqttServiceInterface;
use App\Service\v3\Interfaces\OrderOfflineServiceInterface; use App\Service\v3\Interfaces\OrderOfflineServiceInterface;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
@ -107,6 +108,12 @@ class NotifyController extends BaseController
*/ */
protected $goodsActivityService; protected $goodsActivityService;
/**
* @Inject
* @var OrderStatisticsServiceInterface
*/
protected $orderStatisticsService;
public function wxminiOnline() public function wxminiOnline()
{ {
@ -163,6 +170,9 @@ class NotifyController extends BaseController
Db::commit(); Db::commit();
//记录当前市场的当天外卖订单数
$this->orderStatisticsService->setForMarket($orderMain->market_id);
// 优惠券返券 // 优惠券返券
$this->couponRebateService->couponRebateInTask($orderMain->global_order_id); $this->couponRebateService->couponRebateInTask($orderMain->global_order_id);

26
app/Controller/v3/OrderOnlineController.php

@ -115,21 +115,30 @@ class OrderOnlineController extends BaseController
$distance_text = '距您收货地址 ' . $distance . 'm'; $distance_text = '距您收货地址 ' . $distance . 'm';
} }
$distributionPrice = $this->distributionPriceService->do($distance); $distributionPrice = $this->distributionPriceService->do($distance);
$originalPrice = $this->distributionPriceService->original($distance);
$res['location'] = [ $res['location'] = [
'address' => $address, 'address' => $address,
'distribution_price' => $distributionPrice, 'distribution_price' => $distributionPrice,
'original_price' => $originalPrice,
'distance' => $distance, 'distance' => $distance,
'within' => true, 'within' => true,
'style' => 'strike',
// 'distribution_text' => '¥ '.$distributionPrice .'(' .$distance_text .')' // 'distribution_text' => '¥ '.$distributionPrice .'(' .$distance_text .')'
'distribution_text' => $distance_text
'distribution_text' => $distance_text,
'distribution_price_text' => '¥ '.$distributionPrice,
'original_price_text' => $originalPrice > $distributionPrice ? '¥ '.$originalPrice : ''
]; ];
}else{ }else{
$res['location'] = [ $res['location'] = [
'address' => '', 'address' => '',
'distribution_price' => 3.5,
'distribution_price' => 0,
'original_price' => 0,
'distance' => $distance, 'distance' => $distance,
'within' => false, 'within' => false,
'distribution_text' => '¥ 3.5'
'style' => 'strike',
'distribution_text' => '',
'distribution_price_text' => '¥ 0',
'original_price_text' => ''
]; ];
} }
//返回预约送达时间 数组 //返回预约送达时间 数组
@ -170,7 +179,16 @@ class OrderOnlineController extends BaseController
$total = bcadd($total,$res['value_added_service']['price'],2); $total = bcadd($total,$res['value_added_service']['price'],2);
$total = bcadd($total,$res['location']['distribution_price'],2); $total = bcadd($total,$res['location']['distribution_price'],2);
$res['total'] = $total; $res['total'] = $total;
//优惠券排序
$collection = collect($res['coupon']['available']);
$sorted = $collection->sortBy(function ($product, $key) use ($total){
if($product['coupon']['discount_type'] == 2){
return bcmul($total,bcdiv($product['coupon']['discounts'],10,2),2);
}elseif($product['coupon']['discount_type'] == 1){
return bcsub($total,$product['coupon']['discounts'],2);
}
});
$res['coupon']['available'] = $sorted->values()->all();
// 新增返回市场信息 // 新增返回市场信息
$res['market'] = $market; $res['market'] = $market;

2
app/Controller/v3/SearchController.php

@ -48,7 +48,7 @@ class SearchController extends BaseController
*/ */
public function goods(SearchGoodsRequest $request) public function goods(SearchGoodsRequest $request)
{ {
$params = $request->validated();
$params = $this->request->all();
$data = $this->searchService->doForGoods($params); $data = $this->searchService->doForGoods($params);
return $this->success($data); return $this->success($data);

5
app/Controller/v3/UserAddressController.php

@ -70,4 +70,9 @@ class UserAddressController extends BaseController
return $this->success(['location' => $res]); return $this->success(['location' => $res]);
} }
public function deliveryDistance(){
$deliveryDistance = config('distance.delivery_distance');
return $this->success(['delivery_distance' => $deliveryDistance]);
}
} }

22
app/Model/v3/Employees.php

@ -0,0 +1,22 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
use Hyperf\Database\Model\Builder;
class Employees extends Model
{
protected $table = 'lanzu_employees';
protected $casts = [
'position' => 'array'
];
protected function boot(): void
{
parent::boot();
self::addGlobalScope('normal', function (Builder $builder) {
$builder->where([$this->getTable().'.status' => 1]);
});
}
}

6
app/Model/v3/Goods.php

@ -109,7 +109,11 @@ class Goods extends Model
public function getCoverImgAttribute($value) public function getCoverImgAttribute($value)
{ {
return $this->attachmentService->switchImgToAliOss($value, OssThumbnail::THUMBNAIL_600_Q90);
if(!empty($value)) {
return $this->attachmentService->switchImgToAliOss($value, OssThumbnail::THUMBNAIL_600_Q90);
}else{
return '';
}
} }
public function getMonthSalesAttribute() public function getMonthSalesAttribute()

17
app/Model/v3/OrderMain.php

@ -57,6 +57,7 @@ class OrderMain extends Model
'pay_time_text', 'pay_time_text',
'pay_type_text', 'pay_type_text',
'shipping_type_text', 'shipping_type_text',
'complete_time_text'
]; ];
protected $casts = [ protected $casts = [
@ -73,10 +74,17 @@ class OrderMain extends Model
return date('Y-m-d H:i:s', $this->attributes['pay_time']); return date('Y-m-d H:i:s', $this->attributes['pay_time']);
} }
public function getCompleteTimeTextAttribute()
{
return date('Y-m-d H:i:s', $this->attributes['complete_time']);
}
public function getStateTextAttribute() public function getStateTextAttribute()
{ {
if ($this->attributes['state'] == 3) {
if (!$this->attributes['horseman_id']) {
if ($this->attributes['state'] == OrderState::DELIVERY) {
if($this->attributes['shipping_type'] == 3) {
return '待自提';
}elseif ($this->attributes['shipping_type'] == 1 && empty($this->attributes['horseman_id'])){
return '已接单'; return '已接单';
} }
} }
@ -130,4 +138,9 @@ class OrderMain extends Model
{ {
return $this->belongsTo(User::class, 'user_id', 'id'); return $this->belongsTo(User::class, 'user_id', 'id');
} }
public function employees()
{
return $this->belongsTo(Employees::class, 'horseman_id', 'id');
}
} }

33
app/Request/v3/EmployeesRequest.php

@ -0,0 +1,33 @@
<?php
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class EmployeesRequest extends BaseFormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'employees_id' => 'required|nonempty|integer',
];
}
/**
* @return array
*/
public function messages(): array
{
return [
'*.*' => ':attribute无效',
];
}
public function attributes(): array
{
return parent::attributes();
}
}

33
app/Request/v3/HorsemanOrderRequest.php

@ -0,0 +1,33 @@
<?php
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class HorsemanOrderRequest extends BaseFormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'global_order_id' => 'required|nonempty|integer',
];
}
/**
* @return array
*/
public function messages(): array
{
return [
'*.*' => ':attribute无效',
];
}
public function attributes(): array
{
return parent::attributes();
}
}

28
app/Service/v3/Implementations/DistributionPriceService.php

@ -22,7 +22,7 @@ class DistributionPriceService implements DistributionPriceServiceInterface
// $distributionPrice = bcmul(0.70,($km-3),2); // $distributionPrice = bcmul(0.70,($km-3),2);
$distributionPrice = 0; $distributionPrice = 0;
break; break;
case ($km > 5 && $km <= 8) :
case ($km > 5 && $km <= $deliveryDistance) :
$distributionPrice = bcmul(1.50,($km-5),2); $distributionPrice = bcmul(1.50,($km-5),2);
break; break;
// case ($km > 7 && $km <= $deliveryDistance) : // case ($km > 7 && $km <= $deliveryDistance) :
@ -44,4 +44,30 @@ class DistributionPriceService implements DistributionPriceServiceInterface
{ {
// TODO: Implement undo() method. // TODO: Implement undo() method.
} }
public function original($distance)
{
$deliveryDistance = config('distance.delivery_distance');
$deliveryDistance = ceil($deliveryDistance/1000);
$km = ceil($distance/1000);
switch (true){
case ($km > $deliveryDistance) :
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE,'',['message' => '超出配送范围', 'data' => ['距离' => $km, '配送距离' => $deliveryDistance]]);
break;
case ($km > 3 && $km <= 5) :
// $distributionPrice = bcmul(0.70,($km-3),2);
$distributionPrice = 0;
break;
case ($km > 5 && $km <= $deliveryDistance) :
$distributionPrice = bcmul(1.50,($km-5),2);
break;
// case ($km > 7 && $km <= $deliveryDistance) :
// $distributionPrice = bcmul(1.50,($km-5),2);
// break;
default:
$distributionPrice = 0;
}
$distributionPrice = bcadd($distributionPrice,3.50,2);
return (float) $distributionPrice;
}
} }

10
app/Service/v3/Implementations/FeiePrintService.php

@ -9,6 +9,7 @@ use App\Model\v3\Feprint;
use App\Model\v3\OrderMain; use App\Model\v3\OrderMain;
use App\Service\v3\Interfaces\FeiePrintServiceInterface; use App\Service\v3\Interfaces\FeiePrintServiceInterface;
use App\Service\v3\Interfaces\HelperServiceInterface; use App\Service\v3\Interfaces\HelperServiceInterface;
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@ -27,6 +28,12 @@ class FeiePrintService implements FeiePrintServiceInterface
*/ */
protected $helperService; protected $helperService;
/**
* @Inject
* @var OrderStatisticsServiceInterface
*/
protected $orderStatistics;
// *必填*:飞鹅云后台注册账号 // *必填*:飞鹅云后台注册账号
const USER = '13161443713@163.com'; const USER = '13161443713@163.com';
// *必填*: 飞鹅云后台注册账号后生成的UKEY 【备注:这不是填打印机的KEY】 // *必填*: 飞鹅云后台注册账号后生成的UKEY 【备注:这不是填打印机的KEY】
@ -218,6 +225,9 @@ class FeiePrintService implements FeiePrintServiceInterface
}else{ }else{
$orderInfo .= '自提时间:' . $arr->delivery_time_note . '<BR>'; $orderInfo .= '自提时间:' . $arr->delivery_time_note . '<BR>';
} }
$orderStatistics = $this->orderStatistics->getForMarket($arr->market_id);
$str = sprintf ("%05d", $orderStatistics); // 生成5位数,不足前面补0
$orderInfo .= '流水号:' . $arr->global_order_id.$str;
//$orderInfo .= '<QR>http://www.feieyun.com</QR>';//把解析后的二维码生成的字符串用标签套上即可自动生成二维码 //$orderInfo .= '<QR>http://www.feieyun.com</QR>';//把解析后的二维码生成的字符串用标签套上即可自动生成二维码
return $orderInfo; return $orderInfo;
} }

48
app/Service/v3/Implementations/HelperService.php

@ -53,4 +53,52 @@ class HelperService implements HelperServiceInterface
return $str; return $str;
} }
/*
* 版本号比较 by sam 20170412
* @param $version1 版本A :5.3.2
* @param $version2 版本B :5.3.0
* @return int -1版本A小于版本B , 0版本A等于版本B, 1版本A大于版本B
*
* 版本号格式注意:
* 1.要求只包含:点和大于等于0小于等于2147483646的整数 的组合
* 2.boole型 true置1,false置0
* 3.不设位默认补0计算,如:版本号5等于版号5.0.0
* 4.不包括数字 负数 的版本号 ,统一按0处理
*
* @example:
* if (versionCompare('5.2.2','5.3.0')<0) {
* echo '版本1小于版本2';
* }
*/
function versionCompare($versionA,$versionB)
{
if ($versionA > 2147483646 || $versionB > 2147483646) {
throw new Exception('版本号,位数太大暂不支持!', '101');
}
$dm = '.';
$verListA = explode($dm, (string)$versionA);
$verListB = explode($dm, (string)$versionB);
$len = max(count($verListA), count($verListB));
$i = -1;
while ($i++ < $len) {
$verListA[$i] = intval(@$verListA[$i]);
if ($verListA[$i] < 0) {
$verListA[$i] = 0;
}
$verListB[$i] = intval(@$verListB[$i]);
if ($verListB[$i] < 0) {
$verListB[$i] = 0;
}
if ($verListA[$i] > $verListB[$i]) {
return 1;
} else if ($verListA[$i] < $verListB[$i]) {
return -1;
} else if ($i == ($len - 1)) {
return 0;
}
}
}
} }

95
app/Service/v3/Implementations/HorsemanService.php

@ -0,0 +1,95 @@
<?php
namespace App\Service\v3\Implementations;
use App\Model\v3\Market;
use App\Model\v3\OrderMain;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\HorsemanServiceInterface;
use Hyperf\Utils\ApplicationContext;
use App\Constants\v3\SsdbKeys;
use App\TaskWorker\SSDBTask;
use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException;
class HorsemanService implements HorsemanServiceInterface
{
public function do()
{
// TODO: Implement do() method.
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function getOrderList($employeesId,$page=1, $pagesize=10)
{
$builder = OrderMain::query()->where(['state' => 3,'horseman_id' => $employeesId]);
$paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize);
$orders = $paginate->toArray();
return [
'has_more_pages' => $paginate->hasMorePages(),
'order_list' => $orders['data']
];
}
/**
* 记录骑手坐标
*/
public function setHorsemanCoordinate($employeesId,$coordinate){
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
if(false === $ssdb->exec('set', SsdbKeys::HORSEMAN_COORDINATE.$employeesId,$coordinate)) {
return false;
}
return true;
}
/**
* 获取骑手坐标
*/
public function getHorsemanCoordinate($employeesId){
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$params = $ssdb->exec('get', SsdbKeys::HORSEMAN_COORDINATE.$employeesId);
if ((false === $params) || empty($params)) {
throw new ErrorCodeException(ErrorCode::HORSEMAN_COORDINATE_FAIL, '骑手正在配送中');
}
return $params;
}
/**
* 获取订单起止坐标
*/
public function getOrderCoordinate($globalOrderId){
//获取订单信息
$order = OrderMain::where('global_order_id',$globalOrderId)
->select(
'lat',
'lng',
'state',
'market_id'
)
->first();
if($order->state != 3)
{
return false;
}
//获取市场信息
$market = Market::where('id',$order->market_id)
->select(
'lat',
'lng'
)
->first();
$res = [
'order' => $order,
'market' => $market
];
return $res;
}
}

2
app/Service/v3/Implementations/OrderListService.php

@ -46,7 +46,7 @@ class OrderListService implements OrderListServiceInterface
{ {
$builder = OrderMain::query() $builder = OrderMain::query()
->with(['orderGoods', 'market'])
->with(['orderGoods', 'market','employees'])
->where(['user_id' => $userId, 'type' => OrderType::ONLINE]); ->where(['user_id' => $userId, 'type' => OrderType::ONLINE]);
switch ($tab) { switch ($tab) {
case 'all': case 'all':

33
app/Service/v3/Implementations/OrderOnlineService.php

@ -12,6 +12,7 @@ use App\Constants\v3\Shipping;
use App\Constants\v3\SsdbKeys; use App\Constants\v3\SsdbKeys;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\Coupon; use App\Model\v3\Coupon;
use App\Model\v3\Employees;
use App\Model\v3\Goods; use App\Model\v3\Goods;
use App\Model\v3\GoodsActivity; use App\Model\v3\GoodsActivity;
use App\Model\v3\Market; use App\Model\v3\Market;
@ -349,9 +350,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface
$couponMoney = bcadd($couponMoney, $coupon->coupon->discounts, 2); $couponMoney = bcadd($couponMoney, $coupon->coupon->discounts, 2);
} elseif ($coupon->coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) { } elseif ($coupon->coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) {
$discountRate = bcdiv($coupon->coupon->discounts,10); $discountRate = bcdiv($coupon->coupon->discounts,10);
$discountRate = bcsub(1,$discountRate);
$discountMoney = bcmul($orderAmount, $discountRate);
$couponMoney = bcadd($couponMoney, $discountMoney, 2);
$discountMoney = bcmul($orderAmount, $discountRate, 2);
$couponMoney = bcsub($orderAmount, $discountMoney, 2);
// $discountRate = bcdiv($coupon->coupon->discounts,10);
// $discountRate = bcsub(1,$discountRate);
// $discountMoney = bcmul($orderAmount, $discountRate);
// $couponMoney = bcadd($couponMoney, $discountMoney, 2);
} }
} }
@ -564,8 +568,9 @@ class OrderOnlineService implements OrderOnlineServiceInterface
public function detailByUser($globalOrderId, $userId) public function detailByUser($globalOrderId, $userId)
{ {
//主订单
$orderMain = OrderMain::with(['market'])->where(['global_order_id' => $globalOrderId])->first(); $orderMain = OrderMain::with(['market'])->where(['global_order_id' => $globalOrderId])->first();
//子订单
$orders = Order::query() $orders = Order::query()
->where(['order_main_id' => $globalOrderId, 'user_id' => $userId]) ->where(['order_main_id' => $globalOrderId, 'user_id' => $userId])
->with([ ->with([
@ -573,8 +578,13 @@ class OrderOnlineService implements OrderOnlineServiceInterface
'store' 'store'
]) ])
->get()->toArray(); ->get()->toArray();
return ['order_main' => $orderMain, 'orders' => $orders];
//配送人员信息
if($orderMain->horseman_id > 0) {
$employees = Employees::query()->where('id', $orderMain->horseman_id)->first();
}else{
$employees = null;
}
return ['order_main' => $orderMain, 'orders' => $orders,'employees' => $employees];
} }
/** /**
@ -734,6 +744,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
{ {
$orderMain = $this->check($globalOrderId, $userId, OrderState::RECEIVING); $orderMain = $this->check($globalOrderId, $userId, OrderState::RECEIVING);
$orderMain->state = OrderState::COMPLETED; $orderMain->state = OrderState::COMPLETED;
$orderMain->complete_time = time();
if (!$orderMain->save()) { if (!$orderMain->save()) {
throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL); throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
} }
@ -849,4 +860,14 @@ class OrderOnlineService implements OrderOnlineServiceInterface
return true; return true;
} }
public function getOrderInfo($globalOrderId)
{
return OrderMain::query()->where('global_order_id',$globalOrderId)->with('market','orderGoods')->first();
}
public function completeForHorseman($globalOrderId)
{
return true;
}
} }

18
app/Service/v3/Implementations/OrderStatisticsService.php

@ -4,10 +4,12 @@
namespace App\Service\v3\Implementations; namespace App\Service\v3\Implementations;
use App\Constants\v3\OrderState; use App\Constants\v3\OrderState;
use App\Constants\v3\OrderType; use App\Constants\v3\OrderType;
use App\Constants\v3\SsdbKeys;
use App\Model\v3\Order; use App\Model\v3\Order;
use App\Model\v3\OrderGoods; use App\Model\v3\OrderGoods;
use App\Model\v3\OrderMain; use App\Model\v3\OrderMain;
use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use App\TaskWorker\SSDBTask;
use Hyperf\Utils\ApplicationContext; use Hyperf\Utils\ApplicationContext;
class OrderStatisticsService implements OrderStatisticsServiceInterface class OrderStatisticsService implements OrderStatisticsServiceInterface
@ -73,4 +75,20 @@ class OrderStatisticsService implements OrderStatisticsServiceInterface
// ->count(); // ->count();
// return $count; // return $count;
} }
public function setForMarket($marketId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$incr = $ssdb->exec('incr', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId);
$expire = strtotime('23:59:59') - time();
$expire = $ssdb->exec('expire', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId,$expire);
return $incr && $expire;
}
public function getForMarket($marketId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$count = $ssdb->exec('get', SsdbKeys::TODAY_SALES_FOR_MARKET.$marketId);
return $count;
}
} }

13
app/Service/v3/Implementations/SearchService.php

@ -28,9 +28,11 @@ class SearchService implements SearchServiceInterface
->where([ ->where([
''.$storeTable.'.is_open' => StoreConstants::IS_OPEN_YES, ''.$storeTable.'.is_open' => StoreConstants::IS_OPEN_YES,
''.$storeTable.'.status' => StoreConstants::STATUS_PASS, ''.$storeTable.'.status' => StoreConstants::STATUS_PASS,
''.$storeTable.'.is_rest' => StoreConstants::IS_REST_NO
])
->where([
]);
if(!isset($params['frompage']) || $params['frompage'] != 'zh_cjdianc/pages/takeout/takeoutindex'){
$builder->where(''.$storeTable.'.is_rest',StoreConstants::IS_REST_NO);
}
$builder->where([
''.$goodsTable.'.market_id' => $params['market_id'], ''.$goodsTable.'.market_id' => $params['market_id'],
''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES ''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES
]) ])
@ -110,12 +112,13 @@ class SearchService implements SearchServiceInterface
$query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
}) })
->whereRaw(''.$goodsTable.'.deleted_at IS NULL') ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
->where([''.$storeTable.'.market_id' => $params['market_id'], ''.$storeTable.'.is_rest' => StoreConstants::IS_REST_NO])
->where([''.$storeTable.'.market_id' => $params['market_id']])
->orderBy($storeTable.'.is_rest','asc');
/*->where('time1', '<=', date('H:i')) /*->where('time1', '<=', date('H:i'))
->where(function ($query) { ->where(function ($query) {
$query->where('time2', '>=', date('H:i')) $query->where('time2', '>=', date('H:i'))
->orWhere('time4', '>=', date('H:i')); ->orWhere('time4', '>=', date('H:i'));
})*/;
})*/
if (isset($params['store_id']) && $params['store_id']) { if (isset($params['store_id']) && $params['store_id']) {
$builder->where([''.$storeTable.'.store_id' => $params['store_id']]); $builder->where([''.$storeTable.'.store_id' => $params['store_id']]);

3
app/Service/v3/Implementations/StoreService.php

@ -82,7 +82,8 @@ class StoreService implements StoreServiceInterface
$query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
}) })
->whereRaw(''.$goodsTable.'.deleted_at IS NULL') ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
->where([''.$storeTable.'.market_id' => $marketId, ''.$storeTable.'.is_rest' => StoreConstants::IS_REST_NO]);
->where([''.$storeTable.'.market_id' => $marketId])
->orderBy($storeTable.'.is_rest','asc');;
$paginate = $builder->groupBy(''.$storeTable.'.id')->orderByDesc($storeTable.'.sales')->paginate($pagesize); $paginate = $builder->groupBy(''.$storeTable.'.id')->orderByDesc($storeTable.'.sales')->paginate($pagesize);
$stores = $paginate->map(function ($item, $key) { $stores = $paginate->map(function ($item, $key) {

11
app/Service/v3/Implementations/TabsService.php

@ -4,10 +4,14 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\Tabs; use App\Constants\v3\Tabs;
use App\Service\v3\Interfaces\TabsServiceInterface; use App\Service\v3\Interfaces\TabsServiceInterface;
use Hyperf\Di\Annotation\Inject;
class TabsService implements TabsServiceInterface class TabsService implements TabsServiceInterface
{ {
/**
* @Inject
* @var HelperService
*/
protected $helperService;
public function do() public function do()
{ {
// TODO: Implement do() method. // TODO: Implement do() method.
@ -25,7 +29,8 @@ class TabsService implements TabsServiceInterface
public function allForAppletIndex($version) public function allForAppletIndex($version)
{ {
if($version == '3.0.12'){
$version = $this->helperService->versionCompare($version,'3.0.12');
if($version >= 0){
return [ return [
['tab' => Tabs::APPLET_INDEX_STORE, 'title' => '推荐店铺', 'subtitle' => '物美价廉', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], ['tab' => Tabs::APPLET_INDEX_STORE, 'title' => '推荐店铺', 'subtitle' => '物美价廉', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '猜你喜欢', 'subtitle' => '我是你的菜', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'], ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '猜你喜欢', 'subtitle' => '我是你的菜', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],

10
app/Service/v3/Implementations/UserAddressService.php

@ -91,16 +91,26 @@ class UserAddressService implements UserAddressServiceInterface
$distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address['address']->lng,$address['address']->lat); $distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address['address']->lng,$address['address']->lat);
$distributionPrice = $this->distributionPriceService->do($distance); $distributionPrice = $this->distributionPriceService->do($distance);
$originalPrice = $this->distributionPriceService->original($distance);
if($distance >= 1000){ if($distance >= 1000){
$distance_text = '距您收货地址 ' . bcdiv($distance,1000,2) . 'km'; $distance_text = '距您收货地址 ' . bcdiv($distance,1000,2) . 'km';
}else{ }else{
$distance_text = '距您收货地址 ' . $distance . 'm'; $distance_text = '距您收货地址 ' . $distance . 'm';
} }
/**
* distributionPrice 配送费
* originalPrice 配送费原价
* style 前端输出样式
*/
$res['address'] = $address; $res['address'] = $address;
$res['delivery_distance'] = $distance; $res['delivery_distance'] = $distance;
$res['distribution_price'] = $distributionPrice; $res['distribution_price'] = $distributionPrice;
$res['original_price'] = $originalPrice;
$res['style'] = 'strike';
// $res['distribution_text'] = '¥ '.$distributionPrice .'(' .$distance_text .')'; // $res['distribution_text'] = '¥ '.$distributionPrice .'(' .$distance_text .')';
$res['distribution_text'] = $distance_text; $res['distribution_text'] = $distance_text;
$res['distribution_price_text'] = '¥ '.$distributionPrice;
$res['original_price_text'] = $originalPrice > $distributionPrice ? '¥ '.$originalPrice : '';
return $res; return $res;
} }

36
app/Service/v3/Implementations/UserCenterBlockService.php

@ -2,6 +2,7 @@
namespace App\Service\v3\Implementations; namespace App\Service\v3\Implementations;
use App\Model\v3\ServicePersonnel;
use App\Service\v3\Interfaces\UserCenterBlockServiceInterface; use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
class UserCenterBlockService implements UserCenterBlockServiceInterface class UserCenterBlockService implements UserCenterBlockServiceInterface
@ -65,18 +66,39 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface
// } // }
if($item['key'] == 'sp'){ if($item['key'] == 'sp'){
$blocks[] = [
'type' => 'sp_user',
'title' => '服务专员',
'items' => [
['name' => '评价', 'icon' => $img_host . 'user_icons/service2.png', 'type' => 'page', 'path' => '/zh_cjdianc/pages/appraise/index?service_personnel_id='.$item['data']['id'],'command'=>'sp_login'],
$tags = [];
if(in_array(29,$item['data']['position'])){
array_push($tags,
[
'name' => '骑手端', 'icon' => $img_host . 'user_icons/service2.png',
'type' => 'page',
'path' => '/pages/deliverymanOrders/deliverymanOrders?employees_id='.$item['data']['id'],
'command'=>'sp_login'
]
);
}
if(in_array(30,$item['data']['position'])){
$personalId = ServicePersonnel::query()->where('user_id',$item['data']['user_id'])->value('id');
array_push($tags,
[
'name' => '评价',
'icon' => $img_host . 'user_icons/service2.png',
'type' => 'page',
'path' => '/zh_cjdianc/pages/appraise/index?service_personnel_id='.$personalId,'command'=>'sp_login'
],
[ [
'name' => '商品管理', 'icon' => $img_host . 'user_icons/service2.png', 'name' => '商品管理', 'icon' => $img_host . 'user_icons/service2.png',
'type' => 'page', 'type' => 'page',
'path' => '/pages/shopList/shopList?personal_id='.$item['data']['id'],
'path' => '/pages/shopList/shopList?personal_id='.$personalId,
'command'=>'sp_login' 'command'=>'sp_login'
] ]
]
);
}
$blocks[] = [
'type' => 'sp_user',
'title' => '服务专员',
'items' => $tags
]; ];
} }

9
app/Service/v3/Implementations/UserInfoService.php

@ -5,6 +5,7 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Constants\v3\SsdbKeys; use App\Constants\v3\SsdbKeys;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\Employees;
use App\Model\v3\User; use App\Model\v3\User;
use App\Model\v3\ServicePersonnel; use App\Model\v3\ServicePersonnel;
use App\Model\v3\Store; use App\Model\v3\Store;
@ -94,10 +95,12 @@ class UserInfoService implements UserInfoServiceInterface
return $store; return $store;
} }
public function getServicePersonnelByUID($userId)
public function getEmployeesByUID($userId)
{ {
$sp = ServicePersonnel::where('user_id',$userId)->select('id','user_id')->first();
return $sp;
$employees = Employees::where('user_id',$userId)->where(function ($query){
$query->whereJsonContains('position', '29')->orWhereJsonContains('position', '30');
})->first();
return $employees;
} }
} }

2
app/Service/v3/Interfaces/DistributionPriceServiceInterface.php

@ -9,4 +9,6 @@ interface DistributionPriceServiceInterface
public function check(); public function check();
public function undo(); public function undo();
public function original($distance);
} }

16
app/Service/v3/Interfaces/HorsemanServiceInterface.php

@ -0,0 +1,16 @@
<?php
namespace App\Service\v3\Interfaces;
interface HorsemanServiceInterface
{
public function do();
public function check();
public function undo();
public function getOrderList($employeesId,$page=1, $pagesize=10);
public function setHorsemanCoordinate($horsemanId,$coordinate);
public function getHorsemanCoordinate($horsemanId);
public function getOrderCoordinate($globalOrderId);
}

9
app/Service/v3/Interfaces/OrderOnlineServiceInterface.php

@ -83,4 +83,13 @@ interface OrderOnlineServiceInterface
* @return mixed * @return mixed
*/ */
public function checkIfBuyFlashGoodsToday($userId); public function checkIfBuyFlashGoodsToday($userId);
/**
* 获取订单详情
* @param $globalOrderId
* @return mixed
*/
public function getOrderInfo($globalOrderId);
public function completeForHorseman($globalOrderId);
} }

2
app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php

@ -10,4 +10,6 @@ interface OrderStatisticsServiceInterface
public function check(); public function check();
public function undo(); public function undo();
public function countOrder($storeId,$type,$startTime = '',$endTime = ''); public function countOrder($storeId,$type,$startTime = '',$endTime = '');
public function getForMarket($marketId);
public function setForMarket($marketId);
} }

2
app/Service/v3/Interfaces/UserInfoServiceInterface.php

@ -9,6 +9,6 @@ interface UserInfoServiceInterface
public function undo($userId); public function undo($userId);
public function detail($userId); public function detail($userId);
public function getStoreByUID($userId); public function getStoreByUID($userId);
public function getServicePersonnelByUID($userId);
public function getEmployeesByUID($userId);
} }

1
config/autoload/dependencies.php

@ -91,4 +91,5 @@ return [
\App\Service\v3\Interfaces\ServiceEvaluateServiceInterface::class => \App\Service\v3\Implementations\ServiceEvaluateService::class, \App\Service\v3\Interfaces\ServiceEvaluateServiceInterface::class => \App\Service\v3\Implementations\ServiceEvaluateService::class,
\App\Service\v3\Interfaces\ParamsTokenServiceInterface::class => \App\Service\v3\Implementations\ParamsTokenSsdbService::class, \App\Service\v3\Interfaces\ParamsTokenServiceInterface::class => \App\Service\v3\Implementations\ParamsTokenSsdbService::class,
\App\Service\v3\Interfaces\GoodsInventoryServiceInterface::class => \App\Service\v3\Implementations\GoodsInventoryService::class, \App\Service\v3\Interfaces\GoodsInventoryServiceInterface::class => \App\Service\v3\Implementations\GoodsInventoryService::class,
\App\Service\v3\Interfaces\HorsemanServiceInterface::class => \App\Service\v3\Implementations\HorsemanService::class,
]; ];

2
config/config.php

@ -62,6 +62,6 @@ return [
'tencent' => env('TENCENT_MAP_KEY', ''), 'tencent' => env('TENCENT_MAP_KEY', ''),
], ],
'distance' => [ 'distance' => [
'delivery_distance' => env('DELIVERY_DISTANCE', '8000')
'delivery_distance' => env('DELIVERY_DISTANCE', '7000')
], ],
]; ];

7
config/routes.php

@ -98,6 +98,13 @@ Router::addGroup('/v3/', function () {
Router::post('paramsToken/analyze', 'App\Controller\v3\ParamsTokenController@analyze'); Router::post('paramsToken/analyze', 'App\Controller\v3\ParamsTokenController@analyze');
Router::post('goods/getTags', 'App\Controller\v3\GoodsController@getTags'); Router::post('goods/getTags', 'App\Controller\v3\GoodsController@getTags');
Router::post('home/market', 'App\Controller\v3\HomeController@marketInfo'); Router::post('home/market', 'App\Controller\v3\HomeController@marketInfo');
Router::post('horseman/getOrderList', 'App\Controller\v3\HorsemanController@getOrderList');
Router::post('horseman/getHorsemanCoordinate', 'App\Controller\v3\HorsemanController@getHorsemanCoordinate');
Router::post('horseman/getOrderCoordinate', 'App\Controller\v3\HorsemanController@getOrderCoordinate');
Router::post('horseman/setHorsemanCoordinate', 'App\Controller\v3\HorsemanController@setHorsemanCoordinate');
Router::post('horseman/getOrderInfo', 'App\Controller\v3\HorsemanController@getOrderInfo');
Router::post('horseman/orderComplete', 'App\Controller\v3\HorsemanController@orderComplete');
Router::post('userAddress/deliveryDistance', 'App\Controller\v3\UserAddressController@deliveryDistance');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由 // 需要登录的路由

Loading…
Cancel
Save