|
@@ -3,7 +3,7 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
-
|
|
|
+use think\Db;
|
|
|
/**
|
|
|
* 核销
|
|
|
*/
|
|
@@ -14,17 +14,212 @@ class Hexiao extends Api
|
|
|
|
|
|
|
|
|
//订单详情
|
|
|
+ //code:order_hexiao_no|2024090466d7c9d5abb1c1
|
|
|
+ //order_no:2024090466d7c9d5abb1c1
|
|
|
public function order_info()
|
|
|
{
|
|
|
+ $code = input('code','');
|
|
|
+ if(strpos($code,'order_hexiao_no|') !== 0){
|
|
|
+ $this->error('识别不到的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_no = substr($code,16);
|
|
|
+
|
|
|
+ $order_info = Db::name('unishop_order')->where('out_trade_no',$order_no)->find();
|
|
|
+ if(empty($order_info)){
|
|
|
+ $this->error('不存在的订单');
|
|
|
+ }
|
|
|
+ if($order_info['status'] != 1){
|
|
|
+ $this->error('非正常的订单');
|
|
|
+ }
|
|
|
+ if($order_info['have_paid'] == 0){
|
|
|
+ $this->error('未支付的订单');
|
|
|
+ }
|
|
|
+ if($order_info['have_received'] != 0){
|
|
|
+ $this->error('该订单已核销');
|
|
|
+ }
|
|
|
+
|
|
|
+ //下面是从unishop/order.php detail方法里拿过来的
|
|
|
+ $order_id = $order_info['id'];
|
|
|
+ $orderModel = new \addons\unishop\model\Order();
|
|
|
+ $order = $orderModel
|
|
|
+ ->with([
|
|
|
+ 'products' => function ($query) {
|
|
|
+ $query->field('id,order_id,image,number,price,spec,title,product_id');
|
|
|
+ },
|
|
|
+ /*'extend' => function ($query) {
|
|
|
+ $query->field('id,order_id,address_id,address_json,express_number,express_company');
|
|
|
+ },
|
|
|
+ 'evaluate' => function ($query) {
|
|
|
+ $query->field('id,order_id,product_id');
|
|
|
+ }*/
|
|
|
+ ])
|
|
|
+ ->where(['id' => $order_id])->find();
|
|
|
+
|
|
|
+ if ($order) {
|
|
|
+ $order = $order->append(['state', 'paidtime'])->toArray();
|
|
|
+
|
|
|
+ // 快递单号
|
|
|
+ /*$order['express_number'] = $order['extend']['express_number'];
|
|
|
+ $order['express_company'] = '快递单号';
|
|
|
+ $order['express'] = '';
|
|
|
+ if (class_exists(\addons\expressquery\library\Expressquery::class)) {
|
|
|
+ $expressInfo = Db::name('expressquery')->where(['express' => $order['extend']['express_company']])->find();
|
|
|
+ $order['express_company'] = $expressInfo['name'] ?? '快递单号';
|
|
|
+ $order['express'] = $expressInfo['express'] ?? '';
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // 送货地址
|
|
|
+ /*$address = json_decode($order['extend']['address_json'], true);
|
|
|
+ $area = (new \addons\unishop\model\Area())
|
|
|
+ ->whereIn('id', [$address['province_id'], $address['city_id'], $address['area_id']])
|
|
|
+ ->column('name', 'id');
|
|
|
+ $delivery['username'] = $address['name'];
|
|
|
+ $delivery['mobile'] = $address['mobile'];
|
|
|
+ $delivery['address'] = $area[$address['province_id']] . ' ' . $area[$address['city_id']] . ' ' . $area[$address['area_id']] . ' ' . $address['address'];
|
|
|
+ $order['delivery'] = $delivery;*/
|
|
|
+
|
|
|
+ // 是否已评论
|
|
|
+// $evaluate = array_column($order['evaluate'], 'product_id');
|
|
|
+ foreach ($order['products'] as &$product) {
|
|
|
+ $product['image'] = cdnurl($product['image']);
|
|
|
+ /*if (in_array($product['id'], $evaluate)) {
|
|
|
+ $product['evaluate'] = true;
|
|
|
+ } else {
|
|
|
+ $product['evaluate'] = false;
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+// unset($order['evaluate']);
|
|
|
+ unset($order['extend']);
|
|
|
+ unset($order['pay_out_trade_no']);
|
|
|
+
|
|
|
+ //预约日期
|
|
|
+ $week_data = [
|
|
|
+ 0 => '周日',
|
|
|
+ 1 => '周一',
|
|
|
+ 2 => '周二',
|
|
|
+ 3 => '周三',
|
|
|
+ 4 => '周四',
|
|
|
+ 5 => '周五',
|
|
|
+ 6 => '周六',
|
|
|
+ 7 => '周日',
|
|
|
+ ];
|
|
|
+ $order['bookdate'] = date('Y-m-d H:i',$order['booktime']) .' '. $week_data[date('w',$order['booktime'])];
|
|
|
+
|
|
|
+ //追加退改规则
|
|
|
+ $order['order_refund_rule'] = config('site.order_refund_rule');
|
|
|
+
|
|
|
+ //电子凭证,核销码
|
|
|
+ /*$qrcode_string = 'order_hexiao_no|' . $order['out_trade_no'];
|
|
|
+ $order['order_hexiao_qrcode'] = httpurllocal($this->inviteimage($qrcode_string));*/
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//追加退改规则
|
|
|
- $this->success();
|
|
|
+ $this->success(1,$order);
|
|
|
}
|
|
|
|
|
|
//完成核销动作
|
|
|
public function hexiao(){
|
|
|
+// $order_id = input('order_id', 0);
|
|
|
+// $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
|
|
|
+ $out_trade_no = input('out_trade_no','');
|
|
|
+
|
|
|
+ $orderModel = new \addons\unishop\model\Order();
|
|
|
+ $order = $orderModel->where(['out_trade_no' => $out_trade_no])->find();
|
|
|
+
|
|
|
+ if (!$order) {
|
|
|
+ $this->error('不存在的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ if($order['status'] != 1){
|
|
|
+ $this->error('非正常的订单');
|
|
|
+ }
|
|
|
+ if($order['have_paid'] == 0){
|
|
|
+ $this->error('未支付的订单');
|
|
|
+ }
|
|
|
+ if($order['have_received'] != 0){
|
|
|
+ $this->error('该订单已核销');
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ $order->have_received = time();
|
|
|
+ $order->hexiao_uid = $this->auth->id;
|
|
|
+ $order->save();
|
|
|
+ $this->success('核销成功');
|
|
|
}
|
|
|
|
|
|
//核销记录
|
|
|
- public function order_list(){}
|
|
|
+ public function order_list(){
|
|
|
+ $orderModel = new \addons\unishop\model\Order();
|
|
|
+
|
|
|
+ $condition = [
|
|
|
+ 'hexiao_uid' => $this->auth->id,
|
|
|
+ 'status' => 1,
|
|
|
+ 'have_paid' => ['gt',0],
|
|
|
+ 'have_delivered' => ['gt',0],
|
|
|
+ 'have_received' => ['gt',0],
|
|
|
+ ];
|
|
|
+ $result = $orderModel
|
|
|
+ ->with([
|
|
|
+ 'products' => function($query) {
|
|
|
+ $query->field('id,title,image,number,price,spec,order_id,product_id');
|
|
|
+ },
|
|
|
+
|
|
|
+ ])
|
|
|
+ ->where($condition)
|
|
|
+ ->order(['have_received' => 'desc'])
|
|
|
+ ->autopage()
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ //预约日期
|
|
|
+ $week_data = [
|
|
|
+ 0 => '周日',
|
|
|
+ 1 => '周一',
|
|
|
+ 2 => '周二',
|
|
|
+ 3 => '周三',
|
|
|
+ 4 => '周四',
|
|
|
+ 5 => '周五',
|
|
|
+ 6 => '周六',
|
|
|
+ 7 => '周日',
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($result as &$item) {
|
|
|
+ $item->append(['order_id','state']);
|
|
|
+ $item = $item->toArray();
|
|
|
+
|
|
|
+ unset($item['pay_out_trade_no']);
|
|
|
+
|
|
|
+ /*$evaluate = array_column($item['evaluate'], 'product_id');
|
|
|
+ $refundProducts = array_column($item['refund_products'], 'order_product_id');
|
|
|
+ unset($item['evaluate']);
|
|
|
+ unset($item['refund_products']);*/
|
|
|
+
|
|
|
+ foreach ($item['products'] as &$product) {
|
|
|
+ $product['image'] = cdnurl($product['image']);
|
|
|
+ // 是否已评论
|
|
|
+ /*if (in_array($product['id'], $evaluate)) {
|
|
|
+ $product['evaluate'] = true;
|
|
|
+ } else {
|
|
|
+ $product['evaluate'] = false;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // 是否退货
|
|
|
+ /*if ($item['refund_status'] == self::REFUND_STATUS_AGREE && in_array($product['order_product_id'], $refundProducts)) {
|
|
|
+ $product['refund'] = true;
|
|
|
+ } else {
|
|
|
+ $product['refund'] = false;
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $item['bookdate'] = date('Y-m-d H:i',$item['booktime']) .' '. $week_data[date('w',$item['booktime'])];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1,$result);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|