123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\service\OrderService;
- use app\common\service\ToolService;
- use think\Exception;
- use think\exception\HttpResponseException;
- use think\Log;
- class Order extends Api
- {
- protected $noNeedLogin = ['payNotify', 'detail'];
- protected $noNeedRight = ['*'];
- /**
- * 列表
- *
- * @ApiMethod (POST)
- * @param string $desc 需求描述
- * @param array $images 图片数组
- * @param array $files 文件数组
- * @param string $contact 联系方式
- */
- public function list()
- {
- try {
- $user_id = $this->auth->id ?? -1;
- $params = $this->request->param('parameter/a', []);
- $page = $params['pageNum'] ?? 1;
- $page_size = $params['pageSize'] ?? 10;
- $order_status = $params['orderStatus'] ?? null;
- $order_type = $params['orderType'] ?? 0;
- $keywords = $params['keywords'] ?? '';
- $where = [
- 'user_id' => $user_id,
- ];
- if ($keywords) {
- $where['order_no'] = $keywords;
- }
- if ($order_type) {
- $where['order_type'] = $order_type;
- }
- if (!is_null($order_status)) {
- $where['order_status'] = $order_status;
- }
- $list = OrderService::getList($where, $page_size, 'id desc', '', ['orderGoods', 'orderPayment'], ['config' => ['page' => $page]]);
- $pageList = $list->toArray();
- $pageList['data'] = convert_keys_to_camelcase($pageList['data']);
- foreach ($pageList['data'] as &$item) {
- $item['status'] = $item['orderStatus'];
- $item['statusName'] = OrderService::ORDER_STATUS_MAP[$item['orderStatus']] ?? '';
- $item['buttonVOs'] = OrderService::getOrderButtons($item['orderStatus']);
- $item['groupInfoVo'] = [];
- $item['freightFee'] = 0;
- }
- $this->success('', $pageList);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- public function count()
- {
- try {
- $data = OrderService::getOrderCount($this->auth->id ?? 0);
- $this->success('', $data);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- public function detail()
- {
- try {
- $orderNo = $this->request->get('order_no', 0);
- $where = [
- 'order_no' => $orderNo
- ];
- $info = OrderService::getOne($where, ['orderPayment', 'orderShip', 'orderGoods'=>function($query){
- $query->with('goodsInfo');
- }]);
- if (!$info) {
- throw new Exception('该订单不存在或已删除');
- }
- //格式转换
- $info = convert_keys_to_camelcase($info->toArray());
- $info['orderStatusName'] = $info['orderStatusText'];
- $info['orderStatusRemark'] = '';
- $info['storeName'] = '商品信息';
- $info['invoiceStatus'] = 3;
- $info['invoiceDesc'] = '';
- $info['formatCreateTime'] = date('Y-m-d H:i', $info['createtime']);
- $info['buttonVOs'] = []; // [['primary' => true, 'type' => 1, 'name' => '付款']],
- $this->success('', $info);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- public function settleDetail()
- {
- try {
- $goodsRequestList = $this->request->post('goodsRequestList/a', []);
- $storeInfoList = $this->request->post('storeInfoList/a', []);
- $couponList = $this->request->post('couponList/a', []);
- $totalSalePrice = 0;
- $totalPayAmount = 0;
- $totalGoodsCount = 0;
- $storeGoodsList = [];
- $goodsList = [];
- foreach ($goodsRequestList as $goods) {
- $totalGoodsCount += $goods['quantity'];
- $totalSalePrice += $goods['quantity'] * $goods['price'];
- $goodsList[] = [
- 'storeId' => $goods['storeId'], // 假设这是从其他地方获取的数据
- 'spuId' => $goods['spuId'],
- 'skuId' => 0,
- 'goodsName' => $goods['goodsName'],
- 'image' => $goods['primaryImage'],
- 'quantity' => $goods['quantity'],
- 'price' => $goods['price'],
- 'settlePrice' => $goods['price'],
- 'originPrice' => $goods['price'],
- 'specInfo' => [
- ],
- 'roomId' => ''
- ];
- $storeGoodsList[] = [
- 'storeId' => $goods['storeId'],
- 'storeName' => '',
- 'remark' => null,
- 'goodsCount' => $goods['quantity'],
- 'deliveryFee' => '0',
- 'deliveryWords' => null,
- 'storeTotalAmount' => $totalSalePrice,
- 'storeTotalPayAmount' => $totalSalePrice,
- 'storeTotalDiscountAmount' => '0',
- 'storeTotalCouponAmount' => '0',
- 'skuDetailVos' => $goodsList,
- 'couponList' => [
- ],
- ];
- }
- $resp = [
- 'settleType' => 1, // 0不可结算 1可结算
- 'userAddress' => null,
- 'totalGoodsCount' => $totalGoodsCount,
- 'packageCount' => 1,
- 'totalAmount' => $totalSalePrice,
- 'totalPayAmount' => $totalSalePrice,
- 'totalDiscountAmount' => 0,
- 'totalPromotionAmount' => 0,
- 'totalCouponAmount' => '0',
- 'totalSalePrice' => $totalSalePrice,
- 'totalGoodsAmount' => $totalSalePrice,
- 'totalDeliveryFee' => '0',
- 'invoiceRequest' => null,
- 'skuImages' => null,
- 'deliveryFeeList' => null,
- 'storeGoodsList' => $storeGoodsList,
- 'inValidGoodsList' => null,
- 'outOfStockGoodsList' => null,
- 'limitGoodsList' => null,
- 'abnormalDeliveryGoodsList' => null,
- 'invoiceSupport' => 1,
- ];
- $this->success('', $resp);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- public function commitPay()
- {
- try {
- $param = $this->request->param();
- $param['userInfo'] = $this->auth->getUserinfo();
- $res = !empty($param['orderNo']) ? OrderService::orderPay($param) : OrderService::createOrder($param);
- $this->success('', $res);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- /**
- * 订单取消
- * @return void
- */
- public function cancelOrder()
- {
- try {
- $orderId = $this->request->param('order_id', 0);
- $userId = $this->auth->id ?? 0;
- $res = OrderService::cancelOrder($orderId, $userId);
- $this->success('', $res);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- /**
- * @param
- */
- public function orderOperate()
- {
- try {
- $param = $this->request->param();
- $userId = $this->auth->id ?? 0;
- $res = OrderService::orderOperate($param, $userId);
- $this->success('', $res);
- } catch (\Exception $e) {
- if ($e instanceof HttpResponseException) {
- throw $e;
- }
- $this->error($e->getMessage());
- }
- }
- /**
- * 支付回调
- * @return void
- * @throws \Exception
- */
- public function payNotify()
- {
- header('Content-Type: text/xml; charset=utf-8');
- try {
- $xml = OrderService::payNotify();
- echo $xml;
- exit;
- } catch (\Exception $e) {
- $res = [
- 'return_code' => 'FAIL',
- 'return_msg' => $e->getMessage()
- ];
- $xml = ToolService::ToXml($res);
- Log::info('微信回调信息信息_result_error:' . json_encode(['res' => $res, 'xml' => $xml], JSON_UNESCAPED_UNICODE));
- echo $xml;
- exit;
- }
- }
- public function businessTime()
- {
- $res = [
- 'businessTime' => ['周一,周二,周三,周四,周五:00:20:00-08:00:00'],
- 'telphone' => '18565372257',
- 'saasId' => '88888',
- ];
- $this->success('Success', $res);
- }
- }
|