diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 11089ab..7e6a60d 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -406,4 +406,14 @@ class ErrorCode extends AbstractConstants * @Message("token解析失败") */ const TOKEN_NOT_EXISTS = 1353; + + /************************************/ + /* 骑手相关 1451-1500 */ + /************************************/ + + /** + * 获取骑手坐标失败 + * @Message("获取骑手坐标失败") + */ + const HORSEMAN_COORDINATE_FAIL = 1451; } \ No newline at end of file diff --git a/app/Constants/v3/SsdbKeys.php b/app/Constants/v3/SsdbKeys.php index f153fb1..bdda500 100644 --- a/app/Constants/v3/SsdbKeys.php +++ b/app/Constants/v3/SsdbKeys.php @@ -80,4 +80,14 @@ class SsdbKeys extends AbstractConstants */ const PARAMS_TOKEN = 'params_token_v3_'; + /** + * @Message("骑手坐标") + */ + const HORSEMAN_COORDINATE = 'horseman_coordinate_'; + + /** + * @Message("市场当日线上订单数量统计") + */ + const TODAY_SALES_FOR_MARKET = 'today_sales_for_market_'; + } \ No newline at end of file diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 7e8bb5c..4ce996b 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -2,7 +2,9 @@ namespace App\Controller\v3; +use App\Constants\v3\ErrorCode; use App\Controller\BaseController; +use App\Exception\ErrorCodeException; use App\Model\v3\Category; use App\Model\v3\GoodsCategory; use App\Request\v3\GoodsEditorRequest; @@ -62,6 +64,10 @@ class GoodsController extends BaseController $res['banner'] = $this->goodsService->getBanner($goodsId); } + //搜索不到商品 + if(is_null($res['detail']['id'])){ + throw new ErrorCodeException(ErrorCode::GOODS_ON_SALE_NO); + } //如果没有banner数据,使用商品cover图 if(count($res['banner']) == 0){ // $res['banner'] = [$res['detail']['cover_img']]; diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index 0224d59..03281c6 100644 --- a/app/Controller/v3/HomeController.php +++ b/app/Controller/v3/HomeController.php @@ -160,10 +160,10 @@ class HomeController extends BaseController $params = $request->validated(); $data['user'] = $this->userInfoService->detail($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']['sp_info'] = $sp_info; + $data['user']['sp_info'] = $employees; $roles = []; @@ -177,12 +177,12 @@ class HomeController extends BaseController ]; } - if($sp_info){ + if($employees){ $roles[] = [ 'key'=>'sp', 'title'=>'服务', 'color'=>'#0091FF', - 'data'=>$sp_info, + 'data'=>$employees, ]; } diff --git a/app/Controller/v3/HorsemanController.php b/app/Controller/v3/HorsemanController.php new file mode 100644 index 0000000..2676eb5 --- /dev/null +++ b/app/Controller/v3/HorsemanController.php @@ -0,0 +1,90 @@ +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); + } + } +} \ No newline at end of file diff --git a/app/Controller/v3/NotifyController.php b/app/Controller/v3/NotifyController.php index f4c8810..bf8e57e 100644 --- a/app/Controller/v3/NotifyController.php +++ b/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\OrderOfflineServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; +use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; @@ -107,6 +108,12 @@ class NotifyController extends BaseController */ protected $goodsActivityService; + /** + * @Inject + * @var OrderStatisticsServiceInterface + */ + protected $orderStatisticsService; + public function wxminiOnline() { @@ -163,6 +170,9 @@ class NotifyController extends BaseController Db::commit(); + //记录当前市场的当天外卖订单数 + $this->orderStatisticsService->setForMarket($orderMain->market_id); + // 优惠券返券 $this->couponRebateService->couponRebateInTask($orderMain->global_order_id); diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index c12bf72..2839970 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -115,21 +115,30 @@ class OrderOnlineController extends BaseController $distance_text = '距您收货地址 ' . $distance . 'm'; } $distributionPrice = $this->distributionPriceService->do($distance); + $originalPrice = $this->distributionPriceService->original($distance); $res['location'] = [ 'address' => $address, 'distribution_price' => $distributionPrice, + 'original_price' => $originalPrice, 'distance' => $distance, 'within' => true, + 'style' => 'strike', // 'distribution_text' => '¥ '.$distributionPrice .'(' .$distance_text .')' - 'distribution_text' => $distance_text + 'distribution_text' => $distance_text, + 'distribution_price_text' => '¥ '.$distributionPrice, + 'original_price_text' => $originalPrice > $distributionPrice ? '¥ '.$originalPrice : '' ]; }else{ $res['location'] = [ 'address' => '', - 'distribution_price' => 3.5, + 'distribution_price' => 0, + 'original_price' => 0, 'distance' => $distance, '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['location']['distribution_price'],2); $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; diff --git a/app/Controller/v3/SearchController.php b/app/Controller/v3/SearchController.php index 9e0c92b..3477e75 100644 --- a/app/Controller/v3/SearchController.php +++ b/app/Controller/v3/SearchController.php @@ -48,7 +48,7 @@ class SearchController extends BaseController */ public function goods(SearchGoodsRequest $request) { - $params = $request->validated(); + $params = $this->request->all(); $data = $this->searchService->doForGoods($params); return $this->success($data); diff --git a/app/Controller/v3/UserAddressController.php b/app/Controller/v3/UserAddressController.php index 0cfdd51..985dcc2 100644 --- a/app/Controller/v3/UserAddressController.php +++ b/app/Controller/v3/UserAddressController.php @@ -70,4 +70,9 @@ class UserAddressController extends BaseController return $this->success(['location' => $res]); } + public function deliveryDistance(){ + $deliveryDistance = config('distance.delivery_distance'); + return $this->success(['delivery_distance' => $deliveryDistance]); + } + } \ No newline at end of file diff --git a/app/Model/v3/Employees.php b/app/Model/v3/Employees.php new file mode 100644 index 0000000..feae515 --- /dev/null +++ b/app/Model/v3/Employees.php @@ -0,0 +1,22 @@ + 'array' + ]; + + protected function boot(): void + { + parent::boot(); + self::addGlobalScope('normal', function (Builder $builder) { + $builder->where([$this->getTable().'.status' => 1]); + }); + } +} \ No newline at end of file diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 13e4411..7ee3cf8 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -109,7 +109,11 @@ class Goods extends Model 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() diff --git a/app/Model/v3/OrderMain.php b/app/Model/v3/OrderMain.php index 3b83f26..d08009a 100644 --- a/app/Model/v3/OrderMain.php +++ b/app/Model/v3/OrderMain.php @@ -57,6 +57,7 @@ class OrderMain extends Model 'pay_time_text', 'pay_type_text', 'shipping_type_text', + 'complete_time_text' ]; protected $casts = [ @@ -73,10 +74,17 @@ class OrderMain extends Model 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() { - 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 '已接单'; } } @@ -130,4 +138,9 @@ class OrderMain extends Model { return $this->belongsTo(User::class, 'user_id', 'id'); } + + public function employees() + { + return $this->belongsTo(Employees::class, 'horseman_id', 'id'); + } } \ No newline at end of file diff --git a/app/Request/v3/EmployeesRequest.php b/app/Request/v3/EmployeesRequest.php new file mode 100644 index 0000000..a4469e0 --- /dev/null +++ b/app/Request/v3/EmployeesRequest.php @@ -0,0 +1,33 @@ + 'required|nonempty|integer', + ]; + } + + /** + * @return array + */ + public function messages(): array + { + return [ + '*.*' => ':attribute无效', + ]; + } + + public function attributes(): array + { + return parent::attributes(); + } +} \ No newline at end of file diff --git a/app/Request/v3/HorsemanOrderRequest.php b/app/Request/v3/HorsemanOrderRequest.php new file mode 100644 index 0000000..8187f1c --- /dev/null +++ b/app/Request/v3/HorsemanOrderRequest.php @@ -0,0 +1,33 @@ + 'required|nonempty|integer', + ]; + } + + /** + * @return array + */ + public function messages(): array + { + return [ + '*.*' => ':attribute无效', + ]; + } + + public function attributes(): array + { + return parent::attributes(); + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/DistributionPriceService.php b/app/Service/v3/Implementations/DistributionPriceService.php index dadca3b..2bab7c5 100644 --- a/app/Service/v3/Implementations/DistributionPriceService.php +++ b/app/Service/v3/Implementations/DistributionPriceService.php @@ -22,7 +22,7 @@ class DistributionPriceService implements DistributionPriceServiceInterface // $distributionPrice = bcmul(0.70,($km-3),2); $distributionPrice = 0; break; - case ($km > 5 && $km <= 8) : + case ($km > 5 && $km <= $deliveryDistance) : $distributionPrice = bcmul(1.50,($km-5),2); break; // case ($km > 7 && $km <= $deliveryDistance) : @@ -44,4 +44,30 @@ class DistributionPriceService implements DistributionPriceServiceInterface { // 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; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/FeiePrintService.php b/app/Service/v3/Implementations/FeiePrintService.php index 5ba59eb..8f0c0f8 100644 --- a/app/Service/v3/Implementations/FeiePrintService.php +++ b/app/Service/v3/Implementations/FeiePrintService.php @@ -9,6 +9,7 @@ use App\Model\v3\Feprint; use App\Model\v3\OrderMain; use App\Service\v3\Interfaces\FeiePrintServiceInterface; use App\Service\v3\Interfaces\HelperServiceInterface; +use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use Hyperf\DbConnection\Db; use Hyperf\Di\Annotation\Inject; @@ -27,6 +28,12 @@ class FeiePrintService implements FeiePrintServiceInterface */ protected $helperService; + /** + * @Inject + * @var OrderStatisticsServiceInterface + */ + protected $orderStatistics; + // *必填*:飞鹅云后台注册账号 const USER = '13161443713@163.com'; // *必填*: 飞鹅云后台注册账号后生成的UKEY 【备注:这不是填打印机的KEY】 @@ -218,6 +225,9 @@ class FeiePrintService implements FeiePrintServiceInterface }else{ $orderInfo .= '自提时间:' . $arr->delivery_time_note . '
'; } + $orderStatistics = $this->orderStatistics->getForMarket($arr->market_id); + $str = sprintf ("%05d", $orderStatistics); // 生成5位数,不足前面补0 + $orderInfo .= '流水号:' . $arr->global_order_id.$str; //$orderInfo .= 'http://www.feieyun.com';//把解析后的二维码生成的字符串用标签套上即可自动生成二维码 return $orderInfo; } diff --git a/app/Service/v3/Implementations/HelperService.php b/app/Service/v3/Implementations/HelperService.php index 72e138d..5458e86 100644 --- a/app/Service/v3/Implementations/HelperService.php +++ b/app/Service/v3/Implementations/HelperService.php @@ -53,4 +53,52 @@ class HelperService implements HelperServiceInterface 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; + } + } + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/HorsemanService.php b/app/Service/v3/Implementations/HorsemanService.php new file mode 100644 index 0000000..66dbb22 --- /dev/null +++ b/app/Service/v3/Implementations/HorsemanService.php @@ -0,0 +1,95 @@ +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; + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/OrderListService.php b/app/Service/v3/Implementations/OrderListService.php index 2f5322a..be1ab0f 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -46,7 +46,7 @@ class OrderListService implements OrderListServiceInterface { $builder = OrderMain::query() - ->with(['orderGoods', 'market']) + ->with(['orderGoods', 'market','employees']) ->where(['user_id' => $userId, 'type' => OrderType::ONLINE]); switch ($tab) { case 'all': diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 8a128d0..158d501 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -12,6 +12,7 @@ use App\Constants\v3\Shipping; use App\Constants\v3\SsdbKeys; use App\Exception\ErrorCodeException; use App\Model\v3\Coupon; +use App\Model\v3\Employees; use App\Model\v3\Goods; use App\Model\v3\GoodsActivity; use App\Model\v3\Market; @@ -349,9 +350,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface $couponMoney = bcadd($couponMoney, $coupon->coupon->discounts, 2); } elseif ($coupon->coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) { $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) { - + //主订单 $orderMain = OrderMain::with(['market'])->where(['global_order_id' => $globalOrderId])->first(); + //子订单 $orders = Order::query() ->where(['order_main_id' => $globalOrderId, 'user_id' => $userId]) ->with([ @@ -573,8 +578,13 @@ class OrderOnlineService implements OrderOnlineServiceInterface 'store' ]) ->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->state = OrderState::COMPLETED; + $orderMain->complete_time = time(); if (!$orderMain->save()) { throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL); } @@ -849,4 +860,14 @@ class OrderOnlineService implements OrderOnlineServiceInterface return true; } + + public function getOrderInfo($globalOrderId) + { + return OrderMain::query()->where('global_order_id',$globalOrderId)->with('market','orderGoods')->first(); + } + + public function completeForHorseman($globalOrderId) + { + return true; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/OrderStatisticsService.php b/app/Service/v3/Implementations/OrderStatisticsService.php index 567c86c..28239e7 100644 --- a/app/Service/v3/Implementations/OrderStatisticsService.php +++ b/app/Service/v3/Implementations/OrderStatisticsService.php @@ -4,10 +4,12 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; +use App\Constants\v3\SsdbKeys; use App\Model\v3\Order; use App\Model\v3\OrderGoods; use App\Model\v3\OrderMain; use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface; +use App\TaskWorker\SSDBTask; use Hyperf\Utils\ApplicationContext; class OrderStatisticsService implements OrderStatisticsServiceInterface @@ -73,4 +75,20 @@ class OrderStatisticsService implements OrderStatisticsServiceInterface // ->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; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index 4768e71..a6bc224 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -28,9 +28,11 @@ class SearchService implements SearchServiceInterface ->where([ ''.$storeTable.'.is_open' => StoreConstants::IS_OPEN_YES, ''.$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.'.on_sale' => GoodsConstants::ON_SALE_YES ]) @@ -110,12 +112,13 @@ class SearchService implements SearchServiceInterface $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); }) ->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(function ($query) { $query->where('time2', '>=', date('H:i')) ->orWhere('time4', '>=', date('H:i')); - })*/; + })*/ if (isset($params['store_id']) && $params['store_id']) { $builder->where([''.$storeTable.'.store_id' => $params['store_id']]); diff --git a/app/Service/v3/Implementations/StoreService.php b/app/Service/v3/Implementations/StoreService.php index 50cb0fc..2ef73e4 100644 --- a/app/Service/v3/Implementations/StoreService.php +++ b/app/Service/v3/Implementations/StoreService.php @@ -82,7 +82,8 @@ class StoreService implements StoreServiceInterface $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); }) ->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); $stores = $paginate->map(function ($item, $key) { diff --git a/app/Service/v3/Implementations/TabsService.php b/app/Service/v3/Implementations/TabsService.php index 2438937..c35e7ff 100644 --- a/app/Service/v3/Implementations/TabsService.php +++ b/app/Service/v3/Implementations/TabsService.php @@ -4,10 +4,14 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\Tabs; use App\Service\v3\Interfaces\TabsServiceInterface; - +use Hyperf\Di\Annotation\Inject; class TabsService implements TabsServiceInterface { - + /** + * @Inject + * @var HelperService + */ + protected $helperService; public function do() { // TODO: Implement do() method. @@ -25,7 +29,8 @@ class TabsService implements TabsServiceInterface public function allForAppletIndex($version) { - if($version == '3.0.12'){ + $version = $this->helperService->versionCompare($version,'3.0.12'); + if($version >= 0){ return [ ['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'], diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index bf374d1..442cee9 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/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); $distributionPrice = $this->distributionPriceService->do($distance); + $originalPrice = $this->distributionPriceService->original($distance); if($distance >= 1000){ $distance_text = '距您收货地址 ' . bcdiv($distance,1000,2) . 'km'; }else{ $distance_text = '距您收货地址 ' . $distance . 'm'; } + /** + * distributionPrice 配送费 + * originalPrice 配送费原价 + * style 前端输出样式 + */ $res['address'] = $address; $res['delivery_distance'] = $distance; $res['distribution_price'] = $distributionPrice; + $res['original_price'] = $originalPrice; + $res['style'] = 'strike'; // $res['distribution_text'] = '¥ '.$distributionPrice .'(' .$distance_text .')'; $res['distribution_text'] = $distance_text; + $res['distribution_price_text'] = '¥ '.$distributionPrice; + $res['original_price_text'] = $originalPrice > $distributionPrice ? '¥ '.$originalPrice : ''; return $res; } diff --git a/app/Service/v3/Implementations/UserCenterBlockService.php b/app/Service/v3/Implementations/UserCenterBlockService.php index 14777b9..c7a389c 100644 --- a/app/Service/v3/Implementations/UserCenterBlockService.php +++ b/app/Service/v3/Implementations/UserCenterBlockService.php @@ -2,6 +2,7 @@ namespace App\Service\v3\Implementations; +use App\Model\v3\ServicePersonnel; use App\Service\v3\Interfaces\UserCenterBlockServiceInterface; class UserCenterBlockService implements UserCenterBlockServiceInterface @@ -65,18 +66,39 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface // } 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', 'type' => 'page', - 'path' => '/pages/shopList/shopList?personal_id='.$item['data']['id'], + 'path' => '/pages/shopList/shopList?personal_id='.$personalId, 'command'=>'sp_login' ] - ] + ); + } + $blocks[] = [ + 'type' => 'sp_user', + 'title' => '服务专员', + 'items' => $tags ]; } diff --git a/app/Service/v3/Implementations/UserInfoService.php b/app/Service/v3/Implementations/UserInfoService.php index 0b08a39..8e2e401 100644 --- a/app/Service/v3/Implementations/UserInfoService.php +++ b/app/Service/v3/Implementations/UserInfoService.php @@ -5,6 +5,7 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\ErrorCode; use App\Constants\v3\SsdbKeys; use App\Exception\ErrorCodeException; +use App\Model\v3\Employees; use App\Model\v3\User; use App\Model\v3\ServicePersonnel; use App\Model\v3\Store; @@ -94,10 +95,12 @@ class UserInfoService implements UserInfoServiceInterface 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; } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php b/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php index 5c9d12f..aa6ea22 100644 --- a/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php +++ b/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php @@ -9,4 +9,6 @@ interface DistributionPriceServiceInterface public function check(); public function undo(); + + public function original($distance); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/HorsemanServiceInterface.php b/app/Service/v3/Interfaces/HorsemanServiceInterface.php new file mode 100644 index 0000000..9debfeb --- /dev/null +++ b/app/Service/v3/Interfaces/HorsemanServiceInterface.php @@ -0,0 +1,16 @@ + \App\Service\v3\Implementations\ServiceEvaluateService::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\HorsemanServiceInterface::class => \App\Service\v3\Implementations\HorsemanService::class, ]; diff --git a/config/config.php b/config/config.php index 106c3e0..c6209b4 100644 --- a/config/config.php +++ b/config/config.php @@ -62,6 +62,6 @@ return [ 'tencent' => env('TENCENT_MAP_KEY', ''), ], 'distance' => [ - 'delivery_distance' => env('DELIVERY_DISTANCE', '8000') + 'delivery_distance' => env('DELIVERY_DISTANCE', '7000') ], ]; diff --git a/config/routes.php b/config/routes.php index 3a80997..f6c339c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -98,6 +98,13 @@ Router::addGroup('/v3/', function () { Router::post('paramsToken/analyze', 'App\Controller\v3\ParamsTokenController@analyze'); Router::post('goods/getTags', 'App\Controller\v3\GoodsController@getTags'); 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]]); // 需要登录的路由