|
|
@@ -126,7 +126,7 @@ class ShopOrderLogic extends BaseLogic
|
|
|
{
|
|
|
$detail = ShopOrders::with(['orderGoods'=>function(Query $query){
|
|
|
$query->field(['sn','goods_name','goods_image','number','service_fee','service_total','company_name','delivery_type','shop_goods_type','goods_specs_inventory_id','specs_type','custom_attribute_items','specs'])->append(['spec_arr','delivery_type_text','shop_goods_type_text']);
|
|
|
- }])->field('id, sn, real_name,mobile, address,address_json,pay_time, paw_way,pay_sn, pay_status, refund_status, refund_transaction_id,create_time,shop_order_type,amount_total, order_amount')
|
|
|
+ }])->withCount('orderlogistic')->field('id, sn, real_name,mobile, address,address_json,pay_time, paw_way,pay_sn, pay_status, refund_status, refund_transaction_id,create_time,shop_order_type,amount_total, order_amount')
|
|
|
->append(['pay_way_text','pay_status_text','refund_status_text'])->where(['sn'=> $params['sn'],'worker_id'=>$params['worker_id']])->findOrEmpty()->toArray();
|
|
|
$orderGoodsArr = [];
|
|
|
$companyNameArr = array_unique(array_column($detail['orderGoods'],'company_name'));
|
|
|
@@ -172,4 +172,83 @@ class ShopOrderLogic extends BaseLogic
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物流详情
|
|
|
+ * @param $params
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function logisticDetail($params): array
|
|
|
+ {
|
|
|
+
|
|
|
+ try{
|
|
|
+ $detail = ShopOrders::with(['orderGoods'=>function(Query $query){
|
|
|
+ $query->field(['sn','shop_goods_id','goods_name','goods_image','company_name','delivery_type','shop_goods_type'])->append(['delivery_type_text','shop_goods_type_text']);
|
|
|
+ },'orderlogistic' =>function (Query $query){
|
|
|
+ $query->field(['id','order_id','express_id','shop_goods_id','logistic_number','logistic_status'])->append(['logistic_status_text']);
|
|
|
+ $query->with('express');
|
|
|
+ }])->field('id, sn')->where(['sn'=> $params['sn'],'worker_id'=>$params['worker_id']])->findOrEmpty()->toArray();
|
|
|
+ if(empty($detail)){
|
|
|
+ throw new \Exception('订单不存在');
|
|
|
+ }
|
|
|
+ $orderGoodsArr = [];
|
|
|
+ $companyNameArr = array_unique(array_column($detail['orderGoods'],'company_name'));
|
|
|
+ foreach($companyNameArr as $val) {
|
|
|
+ $orderGoods = [];
|
|
|
+ foreach ($detail['orderGoods'] as $goodVal) {
|
|
|
+ if($val == $goodVal['company_name'] && !isset($orderGoods[$goodVal['shop_goods_id']])){
|
|
|
+ unset($goodVal['goodsSpecsInventory'], $goodVal['custom_attribute_items'], $goodVal['specs'], $goodVal['sn'], $goodVal['goods_specs_inventory_id'],$goodVal['company_name']);
|
|
|
+ $goodVal['logistic'] = [];
|
|
|
+ foreach($detail['orderlogistic'] as $logisticVal){
|
|
|
+ if($goodVal['shop_goods_id'] == $logisticVal['shop_goods_id']){
|
|
|
+ $logisticVal['expresss_name'] = $logisticVal['express']['name'];
|
|
|
+ unset($logisticVal['express']);
|
|
|
+ $goodVal['logistic'][] = $logisticVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $orderGoods[$goodVal['shop_goods_id']] = $goodVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!empty($orderGoods)){
|
|
|
+ $orderGoodsArr[] = [
|
|
|
+ 'company_name' => $val,
|
|
|
+ 'goods' =>array_values( $orderGoods)
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $orderGoodsArr;
|
|
|
+ } catch(\Exception $e){
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认收货
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function confirmReceipt($params):bool
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ Db::startTrans();
|
|
|
+ $orderModel = ShopOrders::where([
|
|
|
+ 'shop_order_type' => 2,
|
|
|
+ 'worker_id' => $params['worker_id'],
|
|
|
+ 'sn'=>$params['sn']
|
|
|
+ ])->findOrEmpty();
|
|
|
+ if($orderModel->isEmpty()){
|
|
|
+ throw new \Exception('订单不存在或不是待收货状态');
|
|
|
+ }
|
|
|
+ $orderModel->shop_order_type = 3;
|
|
|
+ $orderModel->save();
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|