// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\controller; use think\response\Json; use app\api\model\Order as OrderModel; use app\api\model\Setting as SettingModel; use app\api\service\User as UserService; use app\api\service\Order as OrderService; use app\common\service\qrcode\Extract as ExtractQRcode; use cores\exception\BaseException; use app\common\model\TransferRecord; use app\common\model\UploadFile; /** * 我的订单控制器 * Class Order * @package app\api\controller */ class Order extends Controller { /** * 我的订单列表 * @param string $dataType 订单类型 * @return Json * @throws BaseException * @throws \think\db\exception\DbException */ public function list(string $dataType): Json { $model = new OrderModel; $list = $model->getList($dataType); // return $this->renderSuccess(compact('list')); $list = $this->renderSuccess(compact('list')); return $list; } public function del() { $model = new OrderModel; $res = $model->del(); if ($res) { return $this->renderSuccess('删除成功'); } return $this->renderError('删除失败'); } public function orderfast() { $model = new OrderModel; $res = $model->orderfast(); if ($res) { return $this->renderSuccess('催单成功'); } return $this->renderError('催单失败'); } /** * 订单详情信息 * @param int $orderId 订单ID * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function detail(int $orderId): Json { // 订单详情 $model = OrderModel::getUserOrderDetail($orderId); //自提时间 // $model->ziti_time = '2024-03-02 22:22:22'; // $model->ziti_status = 0;//0没提 1已提货 // $model->ziti_image = ['https://www.saas.njrenzhou.com/uploads/10001/20240116/18adc22ad9ea021ab2586878fe1035b0.png']; return $this->renderSuccess([ 'order' => $model, // 订单详情 'setting' => [ // 积分名称 'points_name' => SettingModel::getPointsName(), ], ]); } /** * 获取物流跟踪信息 * @param int $orderId 订单ID * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function expressSearch(string $expressNo): Json { $items = [ [ 'time' => "2021-12-15 17:19:28", "context"=>"【杭州市】您的包裹已存放至【驿站】,记得早点来取它回家!", "ftime"=>"2021-12-15 17:19:28", "areaCode"=>"CN330102000000",//本数据元对应的行政区域编码,resultv2=1或者resultv2=4才会展示 "areaName"=>"浙江,杭州市,上城区",//本数据元对应的行政区域名称,resultv2=1或者resultv2=4才会展示 "status"=>"投柜或驿站",//本数据元对应的物流状态名称或者高级物流状态名称,resultv2=1或者resultv2=4才会展示 "location"=>"浙江省 杭州市 上城区", //本数据元对应的快件当前地点,resultv2=4才会展示 "areaCenter"=>"120.184349,30.25446", //本数据元对应的行政区域经纬度,resultv2=4才会展示 "areaPinYin"=>"shang cheng qu",//本数据元对应的行政区域拼音,resultv2=4才会展示 "statusCode"=>"501",//本数据元对应的高级物流状态值,resultv2=4才会展示 ], ]; $express['items'] = $items; $express['express_name'] = "顺丰"; $express['express_no'] = "1222222222222"; return $this->renderSuccess($express); } /** * 获取物流跟踪信息 * @param int $orderId 订单ID * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function express(int $orderId): Json { $service = new OrderService; $express = $service->express($orderId); return $this->renderSuccess(compact('express')); } /** * 取消订单 * @param int $orderId * @return Json * @throws BaseException */ public function cancel(int $orderId): Json { $model = OrderModel::getDetail($orderId); if ($model->cancel()) { return $this->renderSuccess($model->getMessage()); } return $this->renderError($model->getError() ?: '订单取消失败'); } /** * 确认收货 * @param int $orderId * @return Json * @throws BaseException */ public function receipt(int $orderId): Json { $model = OrderModel::getDetail($orderId); if ($model->receipt()) { return $this->renderSuccess('确认收货成功'); } return $this->renderError($model->getError()); } /** * 获取当前用户行为数量 * @return Json * @throws BaseException */ public function actionCounts(): Json { // $model = new OrderModel; // $counts = $model->getTodoCounts(); $data = [ 'reservation_number' => 1, 'view_number' => 0, 'send_number' => 0, 'integral_number' => 0, 'coupon_number' => 0, 'goods_collect_number' => 0, 'cart_number' => 0, 'take_goods_number' => 1, ]; return $this->renderSuccess($data); } /** * 获取当前用户待处理的订单数量 * @return Json * @throws BaseException */ public function todoCounts(): Json { // $model = new OrderModel; // $counts = $model->getTodoCounts(); $data = [ 'goods_order' => [ 'payment_number' => 0, 'delivery_number' => 0, 'received_number' => 0, 'finish_number' => 0, ], 'service_order' => [ 'confirm_number' => 0, 'service_number' => 0, 'payment_number' => 0, 'check_number' => 0, ], 'distribution_order' => [ 'payment_number' => 0, 'delivery_number' => 0, 'received_number' => 0, 'finish_number' => 0, 'retund_number' => 0, ], ]; return $this->renderSuccess($data); } /** * 获取自提核销二维码 * @param int $orderId * @param string $channel 二维码渠道(小程序码、h5码) * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function extractQrcode(int $orderId, string $channel = 'H5'): Json { // 订单详情 $order = OrderModel::getDetail($orderId); // 判断是否为待核销订单 if (!$order->checkExtractOrder($order)) { return $this->renderError($order->getError()); } // 当前用户信息 $userInfo = UserService::getCurrentLoginUser(); // 创建二维码 $Qrcode = new ExtractQRcode($userInfo, $orderId, $channel); return $this->renderSuccess(['qrcode' => $Qrcode->getImage()]); } /** * 调货列表 * @return Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function transferList(): Json { $params = $this->request->param(); $where = []; if (!empty($params['search'])) { $where[] = ['goods_sn', 'like', "%{$params["search"]}%"]; } $list = TransferRecord::where('status',1) ->where($where) ->order("id desc") ->paginate(10)->each(function ($item, $key) { $goods_sn = explode("、", $item['goods_sn']); $goods_num = explode("、", $item['goods_num']); $goods_price = explode("、", $item['goods_price']); $goods = []; $total_price = 0; foreach ($goods_sn as $seq => $value) { $price = (float)$goods_price[$seq] ?? 0.00; $goods[] = [ 'name' => $value, 'price' => $price, 'num' => $goods_num[$seq] ?? 0, "image" =>'https://imgservice5.suning.cn/uimg1/b2c/image/nXmtUUkwKxasCEBIX90d7w.png' ]; $total_price += $price; } $item['goods'] = $goods; $item['total_price'] = $total_price; $transfer_image_ids = UploadFile::whereIn('file_id', explode(",", $item['transfer_image_id']))->field('file_id,file_path,file_type,storage,domain')->select(); foreach ($transfer_image_ids as &$transfer_image_id) { $transfer_image_id['file_path'] = getUrl($transfer_image_id['file_path'],$transfer_image_id['domain']); } $chat_image_ids = UploadFile::whereIn('file_id', explode(",", $item['chat_image_id']))->field('file_id,file_path,file_type,storage,domain')->select(); foreach ($chat_image_ids as &$chat_image_id) { $chat_image_id['file_path'] = getUrl($chat_image_id['file_path'], $chat_image_id['domain']); } $item['transfer_image_ids'] = $transfer_image_ids; $item['chat_image_ids'] = $chat_image_ids; return $item; })->toArray(); return $this->renderSuccess($list); } public function editTransfer(): Json { $params = $this->request->param(); $id = $params['id']??0; unset($params['id']); TransferRecord::where('id',$id)->update($params); return $this->renderSuccess('ok'); } public function addTransfer(): Json { $params = $this->request->param(); $storeid = request()->header()['storeid']; $params['user_id'] = \app\api\service\User::getCurrentLoginUserId(); $params['store_id'] = $storeid; TransferRecord::create($params); return $this->renderSuccess('ok'); } }