|
@@ -0,0 +1,228 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+
|
|
|
+ * 核销
|
|
|
+ */
|
|
|
+class Hexiao extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = [];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function order_info()
|
|
|
+ {
|
|
|
+ if($this->auth->is_hexiao != 1){$this->error('没有核销权限');}
|
|
|
+
|
|
|
+ $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('该订单已核销');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $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');
|
|
|
+ },
|
|
|
+
|
|
|
+ ])
|
|
|
+ ->where(['id' => $order_id])->find();
|
|
|
+
|
|
|
+ if ($order) {
|
|
|
+ $order = $order->append(['state', 'paidtime'])->toArray();
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($order['products'] as &$product) {
|
|
|
+ $product['image'] = cdnurl($product['image']);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $order['order_hexiao_qrcode'] = httpurllocal($this->inviteimage($qrcode_string));*/
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->success(1,$order);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function hexiao(){
|
|
|
+ if($this->auth->is_hexiao != 1){$this->error('没有核销权限');}
|
|
|
+
|
|
|
+ $code = input('code','');
|
|
|
+ if(strpos($code,'order_hexiao_no|') !== 0){
|
|
|
+ $this->error('识别不到的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ $out_trade_no = substr($code,16);
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $order = Db::name('unishop_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
|
|
|
+
|
|
|
+ if (!$order) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('不存在的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ if($order['status'] != 1){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('非正常的订单');
|
|
|
+ }
|
|
|
+ if($order['have_paid'] == 0){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('未支付的订单');
|
|
|
+ }
|
|
|
+ if($order['have_received'] != 0){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('该订单已核销');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $update = [
|
|
|
+ 'have_received' => time(),
|
|
|
+ 'hexiao_uid' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $order_rs = Db::name('unishop_order')->where('id',$order['id'])->update($update);
|
|
|
+ if($order_rs === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('核销失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $bili = config('site.unishop_order_hexiaomoney_bili');
|
|
|
+
|
|
|
+ $money = bcdiv(bcmul($order['total_price'],$bili,2),100,2);
|
|
|
+
|
|
|
+ if($money > 0){
|
|
|
+ $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'hexiaomoney',$money,10,'核销订单:'.$out_trade_no,'unishop_order',$order['id']);
|
|
|
+ if($rs_wallet['status']===false)
|
|
|
+ {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('核销成功');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function order_list(){
|
|
|
+ if($this->auth->group_id != 3){$this->error('你是不是来错地方了?');}
|
|
|
+
|
|
|
+ $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']);
|
|
|
+
|
|
|
+
|
|
|
+ $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']);
|
|
|
+
|
|
|
+
|
|
|
+ $product['evaluate'] = true;
|
|
|
+ } else {
|
|
|
+ $product['evaluate'] = false;
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $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);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|