wesmiler 6 лет назад
Родитель
Сommit
0fb7a2a732

+ 30 - 0
public/static/weixin/js/print-order.js

@@ -98,6 +98,36 @@ var app = new Vue({
                     _this.getDataList(0);
                 }
             }, "json");
+        },
+        // 取消打印
+        cancel: function(id){
+            var _this = this;
+            if(_this.submitting){
+                return false;
+            }
+
+            if(id<=0 || id == ''){
+                $.showLoading("订单参数错误...");
+                _this.getDataList(0);
+                return false;
+            }
+
+            if(!confirm('是否确定取消该订单的打印任务?')){
+                return false;
+            }
+
+            $.showLoading("处理中请耐心等候...");
+            $.post('/weixin/print/cancel', {id: id}, function (res) {
+                $.hideLoading();
+                if (res.code == 'success') {
+                    $.toast('取消成功,支付金额已退回账户余额');
+                }else if(res.code == 'login'){
+                    login(res.data.url);
+                }else{
+                    $.toast(res.message);
+                    _this.getDataList(0);
+                }
+            }, "json");
         }
     }
 })

+ 21 - 2
public/themes/admin_simpleboot3/admin/order/index.html

@@ -1,4 +1,16 @@
 <include file="public@header"/>
+<style>
+    .count {
+        margin: 1rem auto;
+    }
+    .count span {
+        margin-right: 1rem;
+    }
+    .count span em {
+        font-style: normal;
+        color: red;
+    }
+</style>
 </head>
 <body>
 <div class="wrap js-check-wrap">
@@ -26,12 +38,19 @@
         <a class="btn btn-warning" href="{:url('order/export')}">导出</a>
         <a class="btn btn-danger" onclick="doDelete()">批量删除</a>
     </form>
+    <div class="count">
+        <span >订单数:{$counts.count|default='0'}</span>
+        <span>总收入:<em>{$counts.total|default='0.00'} 元</em></span>
+        <span><php> echo date('Y'); </php>年收入:<em>{$counts.year|default='0.00'} 元</em></span>
+        <span><php> echo date('Y'); </php>年第<php> echo ceil(date('m')/3);</php>季度收入:<em>{$counts.quarter|default='0.00'} 元</em></span>
+        <span><php> echo date('Y年m月'); </php>收入:<em>{$counts.month|default='0.00'} 元</em></span>
+    </div>
     <form method="post" class="js-ajax-form">
         <table class="table table-hover table-bordered">
             <thead>
             <tr>
                 <th><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">全选</th>
-                <th>订单号</th>
+                <th width="100">订单号</th>
                 <th width="80">下单人名称</th>
                 <th>商品</th>
                 <th>积分价格</th>
@@ -40,7 +59,7 @@
                 <th width="60">支付方式</th>
                 <th width="80">收货信息</th>
                 <th width="60">备注</th>
-                <th width="60">兑换时间</th>
+                <th width="120">兑换时间</th>
                 <th>{:lang('STATUS')}</th>
                 <th width="100">{:lang('ACTIONS')}</th>
             </tr>

+ 1 - 0
public/themes/default/weixin/order/prints.html

@@ -32,6 +32,7 @@
                     <div class="title">
                         <span class="no">订单编号:{{item.order_sn}}</span>
                         <span class="status" v-if="item.status == 1">待支付</span>
+                        <span class="status delivery" v-else-if="item.status == 2" @click="cancel(item.id)">取消打印</span>
                         <span class="status delivery" v-else-if="item.status == 2" @click="rePrint(item.id)">打印取件</span>
                         <span class="status success" v-else-if="item.status == 3">已完成</span>
                         <span class="status error" v-else-if="item.status == 5">已取消</span>

+ 28 - 3
vendor/thinkcmf/cmf-app/src/admin/controller/OrderController.php

@@ -37,7 +37,7 @@ class OrderController extends AdminBaseController
         $this->assign($data);
 
         session('search', $data);
-        $list = Db::name('exchange_orders')->alias('o')
+        $query = Db::name('exchange_orders')->alias('o')
             ->join('user u', 'u.id=o.user_id', 'left')
             ->join('exchange_goods g', 'g.order_id=o.id', 'left')
             ->field('o.id,o.order_sn,o.shop_uid,o.user_id,g.goods_name,g.thumb,o.score,o.nums,o.total,o.pay_type,o.created_at,o.realname,o.mobile,o.address,o.remark,o.status,u.user_login,u.real_name')
@@ -55,8 +55,8 @@ class OrderController extends AdminBaseController
                 if($startTime){
                     $query->where('o.created_at', 'egt', $startTime);
                 }
-            })
-            ->order("o.created_at desc")
+            });
+        $list = $query->order("o.created_at desc")
             ->paginate(10)
             ->each(function ($item, $k) {
                 $item['created_at'] = date('y-m-d H:i', strtotime($item['created_at']));
@@ -65,8 +65,33 @@ class OrderController extends AdminBaseController
                 return $item;
             });
 
+
+        $month = ceil(date('m')/3);
+        $monthStart = ($month-1)>0? ($month-1)*3 : 1;
+        $counts['total'] = $query->order("o.created_at desc")->sum('total');
+
+        $counts['year'] = $query->where('o.created_at','>=',date('Y-1-1'))
+            ->where('o.created_at','<=',date('Y-12-31'))
+            ->order("o.created_at desc")
+            ->sum('total');
+
+        $counts['quarter'] = $query->where('o.created_at','>=',date('Y-'.$monthStart.'-1'))
+            ->where('o.created_at','<=',date('Y-'.($month*3).'-31'))
+            ->order("o.created_at desc")
+            ->sum('total');
+
+        $counts['month'] = $query->where('o.created_at','>=',date('Y-m-1'))
+            ->where('o.created_at','<=',date('Y-m-31'))
+            ->order("o.created_at desc")
+            ->sum('total');
+
+        $data = $list? $list->toArray() : [];
+        $counts['count'] = isset($data['total'])? $data['total'] : 0;
+
+
         // 获取分页显示
         $page = $list->render();
+        $this->assign('counts', $counts);
         $this->assign('list', $list);
         $this->assign('page', $page);
         // 渲染模板输出

+ 78 - 1
vendor/thinkcmf/cmf-app/src/weixin/controller/PrintController.php

@@ -34,6 +34,7 @@ class PrintController extends BaseController
      * 图片打印
      */
     public function photo(){
+        FileLogs::where(['user_id'=> $this->userId,'type'=> 1])->update(['status'=> 2]);
         return $this->fetch();
     }
 
@@ -41,6 +42,7 @@ class PrintController extends BaseController
      * 证件打印
      */
     public function papers(){
+        FileLogs::where(['user_id'=> $this->userId,'type'=> 2])->update(['status'=> 2]);
         $this->assign('version', date('YmdHis'));
         return $this->fetch();
     }
@@ -49,6 +51,7 @@ class PrintController extends BaseController
      * 文件打印
      */
     public function files(){
+        FileLogs::where(['user_id'=> $this->userId,'type'=> 3])->update(['status'=> 2]);
         return $this->fetch();
     }
 
@@ -139,7 +142,7 @@ class PrintController extends BaseController
         $id = input('id',0);
 
         $orderInfo = db('orders')->where(['id'=> $id])
-            ->field('id,order_sn,user_id,status')
+            ->field('id,order_sn,user_id,pay_at,status')
             ->find();
         $orderSn = isset($orderInfo['order_sn'])? $orderInfo['order_sn'] : '';
         if(empty($orderInfo) || empty($orderSn)){
@@ -163,6 +166,80 @@ class PrintController extends BaseController
         showJson(1005, 3015, $data);
     }
 
+    /**
+     * 取消订单
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function cancel(){
+        $id = input('id',0);
+
+        $orderInfo = db('orders')->where(['id'=> $id])
+            ->field('id,order_sn,user_id,pay_total,transaction_id,status')
+            ->find();
+        $orderSn = isset($orderInfo['order_sn'])? $orderInfo['order_sn'] : '';
+        if(empty($orderInfo) || empty($orderSn)){
+            showJson(1004,4010);
+        }
+
+        $orserStatus = isset($orderInfo['status'])? $orderInfo['status'] : 0;
+        if($orserStatus != 2){
+            $msgCode = 4010+$orserStatus;
+            showJson(1004,$msgCode);
+        }
+
+        $orserUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0;
+        if($orserUserId != $this->userId){
+            showJson(1004, 2009);
+        }
+
+        db('orders')->startTrans();
+        if(!db('orders')->where(['id'=> $id])->update(['status'=> 5,'remark'=> '用户手动取消订单'])){
+            showJson(1004, 4024);
+            db('orders')->rollback();
+        }
+
+        // 退还金额
+        $payTotal = isset($orderInfo['pay_total'])? floatval($orderInfo['pay_total']) : 0;
+        if($payTotal){
+            $balance = Member::where(['id' => $this->userId])->value('balance');
+            $updateData = [
+                'balance' => moneyFormat($balance + $payTotal, 2),
+                'updated_at' => date('Y-m-d H:i:s'),
+            ];
+
+            if (db('user')->where(['id' => $this->userId])->update($updateData)) {
+                $transactionId = isset($orderInfo['transaction_id']) ? $orderInfo['transaction_id'] : '';
+                $payAt = isset($orderInfo['pay_at']) ? $orderInfo['pay_at'] : '';
+                $log = [
+                    'type' => 1,
+                    'change_type' => 3,
+                    'user_id' => $this->userId,
+                    'create_time' => time(),
+                    'change' => moneyFormat($payTotal, 2),
+                    'balance' => $balance,
+                    'description' => '订单号:' . $orderSn . ',交易单号:' . $transactionId . ',交易时间: ' . $payAt,
+                    'remark' => '订单已支付为打印用户手动申请退款',
+                    'status' => 2
+                ];
+
+                $res = db('user_balance_log')->insertGetId($log);
+                if(!$res){
+                    showJson(1004, 4025);
+                    db('orders')->rollback();
+                }
+            }else{
+                showJson(1004, 4025);
+                db('orders')->rollback();
+            }
+        }
+        db('orders')->commit();
+
+        showJson(1004, 4026);
+    }
 }
 
 

+ 2 - 2
vendor/thinkcmf/cmf-app/src/weixin/controller/UploadController.php

@@ -59,8 +59,8 @@ class UploadController extends BaseController
                         'file_type'=> isset($fileData['file_type'])? $fileData['file_type'] : '',
                         'created_at'=> date('Y-m-d H:i:s')
                     ];
-                    
-                    if($id){
+
+                    if($id || $id = FileLogs::where(['task_key'=> $taskKey])->value('id')){
                 		FileLogs::where(['id'=> $id])->update($data);
                 	}else{
                 		$imgList[] = $data;

+ 3 - 0
vendor/thinkcmf/cmf/src/lang/zh-cn.php

@@ -149,6 +149,9 @@ return [
     '4021'=> '发货成功',
     '4022'=> '发货失败',
     '4023'=> '设备不支持该颜色打印,请更换设备',
+    '4024'=> '订单取消失败,请刷新重试或联系管理员',
+    '4025'=> '订单取消处理失败,请刷新重试或联系管理员',
+    '4026'=> '订单取消打印成功,支付金额已退回余额',
 
     /* 提现 */
     '5001'=> '账户余额不足',