hrjy 2 years ago
parent
commit
79c4bff870

+ 37 - 0
app/admin/controller/ump/WriteOff.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\admin\controller\ump;
+
+use app\admin\controller\AuthController;
+use app\admin\model\store\StoreCategory as CategoryModel;
+use app\admin\model\system\SystemStore;
+use think\facade\Route as Url;
+use app\admin\model\wechat\WechatUser as UserModel;
+
+use crmeb\services\{FormBuilder as Form, UtilService as Util, JsonService as Json};
+
+/**
+ * 优惠券控制器
+ * Class StoreCategory
+ * @package app\admin\controller\system
+ */
+class WriteOff extends AuthController
+{
+
+    /**
+     * @return mixed
+     */
+    public function index()
+    {
+        $where = Util::getMore([
+            ['status', ''],
+            ['title', ''],
+            ['type','']
+        ], $this->request);
+        $this->assign('where', $where);
+        $this->assign(\app\admin\model\ump\WriteOff::systemPage($where));
+        return $this->fetch();
+    }
+
+
+}

+ 61 - 0
app/admin/model/ump/WriteOff.php

@@ -0,0 +1,61 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/11
+ */
+
+namespace app\admin\model\ump;
+
+use crmeb\services\FormBuilder as Form;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+use think\facade\Route as Url;
+use app\admin\model\store\StoreCategory as CategoryModel;
+
+
+/**
+ * Class StoreCategory
+ * @package app\admin\model\store
+ */
+class WriteOff extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'write_off';
+
+    use ModelTrait;
+
+
+    /**
+     * @param $where
+     * @return array
+     */
+    public static function systemPage($where)
+    {
+        $model = new self;
+        $model = $model->alias('a')
+            ->field('a.*,b.nickname,c.coupon_title,c.coupon_price,d.name as d_name')
+            ->leftJoin('user b', 'b.uid = a.uid')
+            ->leftJoin('store_coupon_user c', 'c.id = a.coupon_id')
+            ->leftJoin('system_store d', 'd.id = c.store_id');
+
+        if ($where['title'] != '') $model = $model->where('b.uid|b.nickname', 'LIKE', "%$where[title]%");
+//        if($where['is_del'] != '')  $model = $model->where('is_del',$where['is_del']);
+        $list = self::page($model, $where);
+        if ($list){
+            foreach ($list['list'] as &$v){
+                $v['add_time'] = $v['add_time'] > 0 ? date('Y-m-d H:i:s', $v['add_time']) : 0;
+            }
+        }
+        return $list;
+    }
+
+}

+ 118 - 0
app/admin/view/ump/write_off/index.php

@@ -0,0 +1,118 @@
+{extend name="public/container"}
+{block name="content"}
+<style>
+    .dropdown-menu li a i{
+        width: 10px;
+    }
+</style>
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox">
+            <div class="ibox-title">
+                <div class="ibox-tools">
+
+                </div>
+            </div>
+            <div class="ibox-content">
+                <div class="row">
+                    <div class="m-b m-l">
+                        <form action="" class="form-inline">
+                            <div class="input-group">
+                                <input type="text" name="title" value="{$where.title}" placeholder="核销员昵称ID" class="input-sm form-control">
+                                <span class="input-group-btn">
+                                    <button type="submit" class="btn btn-sm btn-primary"> <i class="fa fa-search" ></i>搜索</button> </span>
+                            </div>
+                        </form>
+                    </div>
+
+                </div>
+                <div class="table-responsive" style="overflow:visible">
+                    <table class="table table-striped  table-bordered">
+                        <thead>
+                        <tr>
+
+                            <th class="text-center">编号</th>
+                            <th class="text-center">核销人</th>
+                            <th class="text-center">优惠券名称</th>
+                            <th class="text-center">优惠券商家</th>
+                            <th class="text-center">优惠券价格</th>
+                            <th class="text-center">核销时间</th>
+                        </tr>
+                        </thead>
+                        <tbody class="">
+                        {volist name="list" id="vo"}
+                        <tr>
+                            <td class="text-center">
+                                {$vo.id}
+                            </td>
+                            <td class="text-center">
+                                {$vo.nickname}
+                            </td>
+                            <td class="text-center">
+                                {$vo.coupon_title}
+                            </td>
+                            <td class="text-center">
+                                {$vo.d_name}
+                            </td>
+                            <td class="text-center">
+                                {$vo.coupon_price}
+                            </td>
+                            <td class="text-center">
+                                {$vo.add_time|date='Y-m-d H:i:s'}
+                            </td>
+                            </td>
+                        </tr>
+                        {/volist}
+                        </tbody>
+                    </table>
+                </div>
+                {include file="public/inner_page"}
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $('.js-group-btn').on('click',function(){
+        $('.js-group-btn').css({zIndex:1});
+        $(this).css({zIndex:100});
+    });
+    $('.del').on('click',function(){
+        window.t = $(this);
+        var _this = $(this),url =_this.data('url');
+        $eb.$swal('delete',function(){
+            $eb.axios.get(url).then(function(res){
+                console.log(res);
+                if(res.status == 200 && res.data.code == 200) {
+                    $eb.$swal('success',res.data.msg);
+//                        _this.parents('tr').remove();
+                }else
+                    return Promise.reject(res.data.msg || '修改失败')
+            }).catch(function(err){
+                $eb.$swal('error',err);
+            });
+        },{'title':'您确定要修改优惠券的状态吗?','text':'修改后将无法恢复并且已发出的优惠券将失效,请谨慎操作!','confirm':'是的,我要修改'})
+    });
+    $('.delstor').on('click',function(){
+        window.t = $(this);
+        var _this = $(this),url =_this.data('url');
+        $eb.$swal('delete',function(){
+            $eb.axios.get(url).then(function(res){
+                console.log(res);
+                if(res.status == 200 && res.data.code == 200) {
+                    $eb.$swal('success',res.data.msg);
+                        _this.parents('tr').remove();
+                }else
+                    return Promise.reject(res.data.msg || '删除失败')
+            }).catch(function(err){
+                $eb.$swal('error',err);
+            });
+        },{'title':'您确定要删除优惠券吗?','text':'删除后将无法恢复,请谨慎操作!','confirm':'是的,我要删除'})
+    });
+    $(".open_image").on('click',function (e) {
+        var image = $(this).data('image');
+        $eb.openImage(image);
+    })
+</script>
+{/block}

+ 8 - 3
app/api/controller/admin/StoreOrderController.php

@@ -2,6 +2,7 @@
 
 namespace app\api\controller\admin;
 
+use app\admin\model\ump\WriteOff;
 use app\Request;
 use app\models\user\{
     User, UserBill
@@ -491,12 +492,11 @@ class StoreOrderController
             ['verify_code', ''],
         ], $request, true);
         if (!$verify_code) return app('json')->fail('缺少核销码');
-        $coupon = StoreCouponUser::where('code', $verify_code)->where('status', 0)->find();
-        $coupons = StoreCoupon::where('id', $coupon['cid'])->find();
+        $coupon = StoreCouponUser::where('code', $verify_code)->where('status', 0)->find(); //用户优惠券
         if (!$coupon) return app('json')->fail('核销的优惠券不存在或已使用或过期');
         $user = SystemStoreStaff::where('uid', $request->uid())->find();
         if (!$user) return app('json')->fail('你不是店员');
-        if ($coupons['store_id'] != $user['store_id']) return app('json')->fail('你不是门店优惠券指定店员,没有权限核销');
+        if ($coupon['store_id'] != $user['store_id']) return app('json')->fail('你不是门店优惠券指定店员,没有权限核销');
         StoreCouponUser::beginTrans();
         try {
             $coupon['status'] = 1;
@@ -506,6 +506,11 @@ class StoreOrderController
             if (count($pon) == 0){
                 StoreOrder::where('order_id', $coupon['order_id'])->update(['use' => 1, 'status' => 3]);
             }
+            WriteOff::create([
+                'uid' => $request->uid(),
+                'coupon_id' => $coupon['id'],
+                'add_time' => time()
+            ]);
             StoreCouponUser::commitTrans();
             if ($res) return app('json')->success('核销成功');
         } catch (\PDOException $e) {