Browse Source

一些功能

Kirin 3 years ago
parent
commit
7e12e63f89
37 changed files with 2724 additions and 269 deletions
  1. 92 1
      app/admin/controller/order/StoreOrder.php
  2. 9 3
      app/admin/controller/store/StoreProduct.php
  3. 11 7
      app/admin/controller/ump/StoreBargain.php
  4. 9 4
      app/admin/controller/ump/StoreCombination.php
  5. 528 0
      app/admin/controller/ump/StoreIntegral.php
  6. 9 5
      app/admin/controller/ump/StoreSeckill.php
  7. 14 4
      app/admin/model/order/StoreOrder.php
  8. 9 5
      app/admin/model/store/StoreProductAttr.php
  9. 365 0
      app/admin/model/ump/StoreIntegral.php
  10. 51 0
      app/admin/model/ump/StoreIntegralAttrResult.php
  11. 53 0
      app/admin/model/ump/StoreIntegralAttrValue.php
  12. 75 30
      app/admin/view/order/store_order/index.php
  13. 22 0
      app/admin/view/store/store_product/create.php
  14. 1 0
      app/admin/view/ump/store_bargain/attr_list.php
  15. 1 0
      app/admin/view/ump/store_combination/attr_list.php
  16. 371 0
      app/admin/view/ump/store_integral/attr.php
  17. 123 0
      app/admin/view/ump/store_integral/attr_list.php
  18. 215 0
      app/admin/view/ump/store_integral/index.php
  19. 104 0
      app/admin/view/ump/store_integral/product_list.php
  20. 1 0
      app/admin/view/ump/store_seckill/attr_list.php
  21. 1 1
      app/admin/view/user/user/index.php
  22. 5 5
      app/api/controller/AuthController.php
  23. 99 0
      app/api/controller/activity/StoreIntegralController.php
  24. 75 0
      app/api/controller/admin/StoreOrderController.php
  25. 11 8
      app/api/controller/order/StoreOrderController.php
  26. 19 17
      app/api/controller/store/StoreCartController.php
  27. 1 1
      app/http/middleware/AllowOriginMiddleware.php
  28. 7 1
      app/http/middleware/AuthTokenMiddleware.php
  29. 151 127
      app/models/store/StoreCart.php
  30. 205 0
      app/models/store/StoreIntegral.php
  31. 62 31
      app/models/store/StoreOrder.php
  32. 1 0
      app/models/user/User.php
  33. 6 6
      crmeb/repositories/OrderRepository.php
  34. 1 1
      public/install/index.php
  35. 1 1
      public/install/index_sae.php
  36. 0 0
      public/install/install.lock
  37. 16 11
      route/api/route.php

+ 92 - 1
app/admin/controller/order/StoreOrder.php

@@ -506,6 +506,27 @@ class StoreOrder extends AuthController
         } else return Json::fail('数据不存在!');
     }
 
+    /**
+     * 修改退押金状态
+     * @param $id
+     * @return \think\response\Json|void
+     */
+    public function refund_deposit_y($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        $product = StoreOrderModel::get($id);
+        if (!$product) return Json::fail('数据不存在!');
+        if ($product['paid'] == 1) {
+            $f = [];
+            $f[] = Form::input('order_id', '退押单号', $product->getData('order_id'))->disabled(1);
+            $f[] = Form::number('refund_price', '退押金额', bcsub($product->getData('deposit'), $product->getData('deposit_back'), 2))->precision(2)->min(0.01);
+//            $f[] = Form::radio('type', '状态', 1)->options([['label' => '直接退押', 'value' => 1], ['label' => '退押后,返回原状态', 'value' => 2]]);
+            $form = Form::make_post_form('退押处理', $f, Url::buildUrl('updateRefundDepositY', array('id' => $id)), 7);
+            $this->assign(compact('form'));
+            return $this->fetch('public/form-builder');
+        } else return Json::fail('数据不存在!');
+    }
+
     /**
      * 退款处理
      * @param $id
@@ -532,7 +553,8 @@ class StoreOrder extends AuthController
         }
         $type = $data['type'];
         unset($data['type']);
-        $refund_data['pay_price'] = $product['pay_price'];
+//        unset($data['refund_price']);
+        $refund_data['pay_price'] = bcadd($product['pay_price'], $product['deposit'], 2);
         $refund_data['refund_price'] = $refund_price;
         if ($product['pay_type'] == 'weixin') {
             if ($product['is_channel'] == 1) {//小程序
@@ -620,6 +642,75 @@ class StoreOrder extends AuthController
         }
     }
 
+
+    /**
+     * 订单退押金
+     * @param Request $request
+     * @return mixed
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function updateRefundDepositY($id)
+    {
+        $data = Util::postMore([
+            'refund_price',
+            ['type', 1],
+        ]);
+        if (!$id) return $this->failed('数据不存在');
+        $product = StoreOrderModel::get($id);
+        if (!$product) return Json::fail('数据不存在!');
+        if ($product['deposit'] == $product['deposit_back']) return Json::fail('已退完押金!不能再退款了');
+        if (!$data['refund_price']) return Json::fail('请输入退款金额');
+        $refund_price = $data['refund_price'];
+        $data['deposit_back'] = bcadd($data['refund_price'], $product['deposit_back'], 2);
+        $bj = bccomp((float)$product['deposit'], (float)$data['deposit_back'], 2);
+        if ($bj < 0) return Json::fail('退押金额大于支付押金,请修改退押金额');
+        if ($data['type'] == 1) {
+            $data['deposit_status'] = 1;
+        } else if ($data['type'] == 2) {
+            $data['deposit_status'] = 0;
+        }
+//        $type = $data['type'];
+        unset($data['type']);
+        unset($data['refund_price']);
+        $refund_data['pay_price'] = bcadd($product['pay_price'], $product['deposit'], 2);
+        $refund_data['refund_price'] = $refund_price;
+
+        if ($product['pay_type'] == 'weixin') {
+            if ($product['is_channel'] == 1) {//小程序
+                try {
+                    MiniProgramService::payOrderRefund($product['order_id'], $refund_data);//2.5.36
+                } catch (\Exception $e) {
+                    return Json::fail($e->getMessage());
+                }
+            } else {//TODO 公众号
+                try {
+                    WechatService::payOrderRefund($product['order_id'], $refund_data);
+                } catch (\Exception $e) {
+                    return Json::fail($e->getMessage());
+                }
+            }
+        } else if ($product['pay_type'] == 'yue') {
+            BaseModel::beginTrans();
+            $usermoney = User::where('uid', $product['uid'])->value('now_money');
+            $res1 = User::bcInc($product['uid'], 'now_money', $refund_price, 'uid');
+            $res2 = UserBill::income('商品退押金', $product['uid'], 'now_money', 'pay_deposit_refund', $refund_price, $product['id'], bcadd($usermoney, $refund_price, 2), '订单退押金到余额' . floatval($refund_price) . '元');
+            $res = $res1 && $res2;
+            BaseModel::checkTrans($res);
+            if (!$res) return Json::fail('余额退押金失败!');
+        }
+        $resEdit = StoreOrderModel::edit($data, $id);
+        if ($resEdit) {
+            StoreOrderStatus::setStatus($id, 'refund_deposit', '退押金给用户' . $refund_price . '元');
+            return Json::successful('修改成功!');
+        } else {
+            StoreOrderStatus::setStatus($id, 'refund_deposit', '退押金给用户' . $refund_price . '元失败');
+            return Json::fail('修改失败!');
+        }
+    }
+
     public function order_info($oid = '')
     {
         if (!$oid || !($orderInfo = StoreOrderModel::get($oid)))

+ 9 - 3
app/admin/controller/store/StoreProduct.php

@@ -197,7 +197,7 @@ class StoreProduct extends AuthController
                 }
                 $productInfo['items'] = $result['attr'] ?? [];
                 $productInfo['attrs'] = $result['value'] ?? [];
-                $productInfo['attr'] = ['pic' => '', 'price' => 0, 'cost' => 0, 'ot_price' => 0, 'stock' => 0, 'bar_code' => '', 'weight' => 0, 'volume' => 0, 'brokerage' => 0, 'brokerage_two' => 0];
+                $productInfo['attr'] = ['pic' => '', 'price' => 0, 'cost' => 0, 'ot_price' => 0, 'stock' => 0, 'bar_code' => '', 'weight' => 0, 'volume' => 0, 'deposit' => 0, 'brokerage' => 0, 'brokerage_two' => 0];
             } else {
                 $result = StoreProductAttrResult::getResult($id);
                 $single = isset($result['value'][0]) ? $result['value'][0] : [];
@@ -212,6 +212,7 @@ class StoreProduct extends AuthController
                     'bar_code' => $single['bar_code'] ?? '',
                     'weight' => $single['weight'] ?? 0,
                     'volume' => $single['volume'] ?? 0,
+                    'deposit' => $single['deposit'] ?? 0,
                     'brokerage' => $single['brokerage'] ?? 0,
                     'brokerage_two' => $single['brokerage_two'] ?? 0,
                 ];
@@ -288,6 +289,7 @@ class StoreProduct extends AuthController
         $data['price'] = min(array_column($detail, 'price'));
         $data['ot_price'] = min(array_column($detail, 'ot_price'));
         $data['cost'] = min(array_column($detail, 'cost'));
+        $data['deposit'] = min(array_column($detail, 'deposit'));
         $attr = $data['items'];
         unset($data['items'], $data['video'], $data['attrs']);
         if (count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
@@ -520,7 +522,7 @@ class StoreProduct extends AuthController
 //            sort($item['detail'], SORT_STRING);
             $suk = implode(',', $item['detail']);
             if ($id) {
-                $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', 0)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two', 'suk');
+                $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', 0)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,deposit,brokerage,brokerage_two', 'suk');
                 if (!count($sukValue)) {
                     $sukValue[$suk]['pic'] = '';
                     $sukValue[$suk]['price'] = 0;
@@ -530,6 +532,7 @@ class StoreProduct extends AuthController
                     $sukValue[$suk]['bar_code'] = '';
                     $sukValue[$suk]['weight'] = 0;
                     $sukValue[$suk]['volume'] = 0;
+                    $sukValue[$suk]['deposit'] = 0;
                     $sukValue[$suk]['brokerage'] = 0;
                     $sukValue[$suk]['brokerage_two'] = 0;
                 }
@@ -542,7 +545,8 @@ class StoreProduct extends AuthController
                 $sukValue[$suk]['bar_code'] = '';
                 $sukValue[$suk]['weight'] = 0;
                 $sukValue[$suk]['volume'] = 0;
-                $sukValue[$suk]['brokerage'] = 0;
+                $sukValue[$suk]['volume'] = 0;
+                $sukValue[$suk]['deposit'] = 0;
                 $sukValue[$suk]['brokerage_two'] = 0;
             }
             foreach (array_keys($detail) as $k => $title) {
@@ -563,6 +567,7 @@ class StoreProduct extends AuthController
             $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
             $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
             $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
+            $valueNew[$count]['deposit'] = $sukValue[$suk]['deposit'] ?? 0;
             $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
             $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
             $count++;
@@ -575,6 +580,7 @@ class StoreProduct extends AuthController
         $header[] = ['title' => '产品编号', 'slot' => 'bar_code', 'align' => 'center', 'minWidth' => 140];
         $header[] = ['title' => '重量(KG)', 'slot' => 'weight', 'align' => 'center', 'minWidth' => 140];
         $header[] = ['title' => '体积(m³)', 'slot' => 'volume', 'align' => 'center', 'minWidth' => 140];
+        $header[] = ['title' => '押金', 'slot' => 'deposit', 'align' => 'center', 'minWidth' => 140];
         $header[] = ['title' => '操作', 'slot' => 'action', 'align' => 'center', 'minWidth' => 70];
         $info = ['attr' => $attr, 'value' => $valueNew, 'header' => $header];
         return Json::successful($info);

+ 11 - 7
app/admin/controller/ump/StoreBargain.php

@@ -14,7 +14,8 @@ use app\admin\model\store\{StoreCategory,
     StoreProductAttr,
     StoreProductAttrResult,
     StoreProduct as ProductModel,
-    StoreProductAttrValue};
+    StoreProductAttrValue
+};
 use crmeb\traits\CurdControllerTrait;
 use think\facade\Route as Url;
 use app\admin\model\system\{SystemAttachment, ShippingTemplates};
@@ -133,7 +134,7 @@ class StoreBargain extends AuthController
         $product = StoreBargainModel::get($id);
         if (!$product) return $this->failed('数据不存在!');
         $f = [];
-        $f[] = Form::input('product_id','产品ID', $product->getData('product_id'))->disabled(true);
+        $f[] = Form::input('product_id', '产品ID', $product->getData('product_id'))->disabled(true);
         $f[] = Form::input('title', '砍价活动名称', $product->getData('title'));
         $f[] = Form::input('info', '砍价活动简介', $product->getData('info'))->type('textarea');
         $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
@@ -277,9 +278,9 @@ class StoreBargain extends AuthController
         if (!$id) return $this->failed('数据不存在');
         $bargain = StoreBargainModel::get($id);
         if (!$bargain) return Json::fail('数据不存在!');
-        if($field == 'rule'){
+        if ($field == 'rule') {
             $data['rule'] = request()->post('rule');
-        }else{
+        } else {
             $data['description'] = request()->post('description');
             StoreDescription::saveDescription($data['description'], $id, 2);
         }
@@ -411,6 +412,7 @@ class StoreBargain extends AuthController
                 $productAttr[0]['bar_code'] = $bargainInfo['bar_code'];
                 $productAttr[0]['weight'] = 0;
                 $productAttr[0]['volume'] = 0;
+                $productAttr[0]['deposit'] = 0;
                 $productAttr[0]['brokerage'] = 0;
                 $productAttr[0]['brokerage_two'] = 0;
                 $productAttr[0]['check'] = 0;
@@ -453,6 +455,7 @@ class StoreBargain extends AuthController
         $price = min(array_column($detail, 'price'));
         $quota = array_sum(array_column($detail, 'quota'));
         $stock = array_sum(array_column($detail, 'stock'));
+        $deposit = min(array_column($detail, 'deposit'));
         if (!$attr) {
             $attr[0]['value'] = '默认';
             $attr[0]['detailValue'] = '';
@@ -460,7 +463,7 @@ class StoreBargain extends AuthController
             $attr[0]['detail'][0] = '默认';
         }
         StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 2);
-        StoreBargainModel::where('id', $data['id'])->update(['stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price,'min_price'=>$min_price]);
+        StoreBargainModel::where('id', $data['id'])->update(['deposit' => $deposit, 'stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price, 'min_price' => $min_price]);
         return Json::successful('添加成功!');
     }
 
@@ -488,12 +491,12 @@ class StoreBargain extends AuthController
         $value = attr_format($attr)[1];
         $valueNew = [];
         $count = 0;
-        $min_price = StoreBargainModel::where('id',$id)->value('min_price');
+        $min_price = StoreBargainModel::where('id', $id)->value('min_price');
         foreach ($value as $key => $item) {
             $detail = $item['detail'];
 //            sort($item['detail'], SORT_STRING);
             $suk = implode(',', $item['detail']);
-            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
+            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,deposit,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
                 foreach (array_values($detail) as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
@@ -509,6 +512,7 @@ class StoreBargain extends AuthController
                 $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
                 $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
                 $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
+                $valueNew[$count]['deposit'] = $sukValue[$suk]['deposit'] ?? 0;
                 $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
                 $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
                 $valueNew[$count]['check'] = $type != 0 ? 1 : 0;

+ 9 - 4
app/admin/controller/ump/StoreCombination.php

@@ -8,12 +8,14 @@ use app\admin\model\store\{StoreCategory,
     StoreProductAttr,
     StoreProductAttrResult,
     StoreProduct as ProductModel,
-    StoreProductAttrValue};
+    StoreProductAttrValue
+};
 use crmeb\traits\CurdControllerTrait;
 use app\admin\model\ump\{StorePink,
     StoreCombinationAttr,
     StoreCombinationAttrResult,
-    StoreCombination as StoreCombinationModel};
+    StoreCombination as StoreCombinationModel
+};
 use think\facade\Route as Url;
 use app\admin\model\system\{SystemAttachment, ShippingTemplates};
 use crmeb\services\{FormBuilder as Form, UtilService as Util, JsonService as Json};
@@ -321,6 +323,7 @@ class StoreCombination extends AuthController
                 $productAttr[0]['bar_code'] = $combinationInfo['bar_code'];
                 $productAttr[0]['weight'] = 0;
                 $productAttr[0]['volume'] = 0;
+                $productAttr[0]['deposit'] = 0;
                 $productAttr[0]['brokerage'] = 0;
                 $productAttr[0]['brokerage_two'] = 0;
                 $productAttr[0]['check'] = 0;
@@ -360,6 +363,7 @@ class StoreCombination extends AuthController
         $price = min(array_column($detail, 'price'));
         $quota = array_sum(array_column($detail, 'quota'));
         $stock = array_sum(array_column($detail, 'stock'));
+        $deposit = min(array_column($detail, 'deposit'));
         if (!$attr) {
             $attr[0]['value'] = '默认';
             $attr[0]['detailValue'] = '';
@@ -367,7 +371,7 @@ class StoreCombination extends AuthController
             $attr[0]['detail'][0] = '默认';
         }
         StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 3);
-        StoreCombinationModel::where('id', $data['id'])->update(['stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price]);
+        StoreCombinationModel::where('id', $data['id'])->update(['deposit' => $deposit, 'stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price]);
         return Json::successful('添加成功!');
     }
 
@@ -543,7 +547,7 @@ class StoreCombination extends AuthController
             $detail = $item['detail'];
 //            sort($item['detail'], SORT_STRING);
             $suk = implode(',', $item['detail']);
-            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
+            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,deposit,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
                 foreach (array_values($detail) as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
@@ -558,6 +562,7 @@ class StoreCombination extends AuthController
                 $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
                 $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
                 $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
+                $valueNew[$count]['deposit'] = $sukValue[$suk]['deposit'] ?? 0;
                 $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
                 $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
                 $valueNew[$count]['check'] = $type != 0 ? 1 : 0;

+ 528 - 0
app/admin/controller/ump/StoreIntegral.php

@@ -0,0 +1,528 @@
+<?php
+
+namespace app\admin\controller\ump;
+
+use app\admin\controller\AuthController;
+use app\admin\model\store\{StoreDescription,
+    StoreProductAttr,
+    StoreProductAttrResult,
+    StoreProduct as ProductModel,
+    StoreProductAttrValue
+};
+use crmeb\traits\CurdControllerTrait;
+use think\Exception;
+use think\exception\ErrorException;
+use think\exception\ValidateException;
+use think\facade\Route as Url;
+use app\admin\model\system\{SystemAttachment, SystemGroupData, ShippingTemplates};
+use app\admin\model\ump\{StoreIntegral as StoreIntegralModel, StoreIntegralAttrResult};
+use crmeb\services\{
+    FormBuilder as Form, UtilService as Util, JsonService as Json
+};
+use app\admin\model\store\StoreCategory;
+
+/**
+ * 限时秒杀  控制器
+ * Class StoreSeckill
+ * @package app\admin\controller\store
+ */
+class StoreIntegral extends AuthController
+{
+
+    use CurdControllerTrait;
+
+    protected $bindModel = StoreIntegralModel::class;
+
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index()
+    {
+        $this->assign('countSeckill', StoreIntegralModel::getSeckillCount());
+        $this->assign('seckillId', StoreIntegralModel::getSeckillIdAll());
+        return $this->fetch();
+    }
+
+    public function save_excel()
+    {
+        $where = Util::getMore([
+            ['status', ''],
+            ['store_name', '']
+        ]);
+        StoreIntegralModel::SaveExcel($where);
+    }
+
+    /**
+     * 异步获取砍价数据
+     */
+    public function get_seckill_list()
+    {
+        $where = Util::getMore([
+            ['page', 1],
+            ['limit', 20],
+            ['status', ''],
+            ['store_name', '']
+        ]);
+        $seckillList = StoreIntegralModel::systemPage($where);
+        if (is_object($seckillList['list'])) $seckillList['list'] = $seckillList['list']->toArray();
+        $data = $seckillList['list']['data'];
+        return Json::successlayui(['count' => $seckillList['list']['total'], 'data' => $data]);
+    }
+
+    public function get_seckill_id()
+    {
+        return Json::successlayui(StoreIntegralModel::getSeckillIdAll());
+    }
+
+    /**
+     * 添加秒杀商品
+     * @return form-builder
+     */
+    public function create()
+    {
+        $f = array();
+        $f[] = Form::frameImageOne('product', '选择商品', Url::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px');
+        $f[] = Form::hidden('product_id', '');
+        $f[] = Form::hidden('description', '');
+        $f[] = Form::input('title', '商品标题');
+        $f[] = Form::input('info', '活动简介')->type('textarea');
+        $f[] = Form::input('unit_name', '单位')->placeholder('个、位');
+        $f[] = Form::select('temp_id', '运费模板')->setOptions(function () {
+            $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
+            $menus = [];
+            foreach ($list['data'] as $menu) {
+                $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
+            }
+            return $menus;
+        })->filterable(1)->col(12);
+        $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
+        $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
+        $f[] = Form::number('sort', '排序')->col(12);
+        $f[] = Form::number('num', '单次购买商品个数')->precision(0)->col(12);
+        $f[] = Form::number('give_integral', '赠送积分')->min(0)->precision(0)->col(12);
+        $f[] = Form::radio('is_hot', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
+        $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 保存秒杀商品
+     * @param int $id
+     */
+    public function save($id = 0)
+    {
+        $data = Util::postMore([
+            'title',
+            'product_id',
+            'info',
+            'unit_name',
+            ['image', ''],
+            ['images', []],
+            ['price', 0],
+            ['ot_price', 0],
+            ['cost', 0],
+            ['sales', 0],
+            ['stock', 0],
+            ['sort', 0],
+            ['give_integral', 0],
+            ['postage', 0],
+            ['is_postage', 0],
+            ['cost', 0],
+            ['is_hot', 0],
+            ['status', 0],
+            ['num', 0],
+            'temp_id',
+            ['weight', 0],
+            ['volume', 0],
+        ]);
+        $data['description'] = StoreDescription::getDescription($data['product_id']);
+        if (!$data['title']) return Json::fail('请输入商品标题');
+        if (!$data['unit_name']) return Json::fail('请输入商品单位');
+        if (!$data['product_id']) return Json::fail('商品ID不能为空');
+        if (!$data['image']) return Json::fail('请选择推荐图');
+        if (count($data['images']) < 1) return Json::fail('请选择轮播图');
+        $data['images'] = json_encode($data['images']);
+        if ($data['num'] < 1) return Json::fail('请输入单次购买个数');
+        if ($id) {
+            unset($data['description']);
+            $product = StoreIntegralModel::get($id);
+            if (!$product) return Json::fail('数据不存在!');
+            StoreIntegralModel::edit($data, $id);
+            return Json::successful('编辑成功!');
+        } else {
+            $data['add_time'] = time();
+            $res = StoreIntegralModel::create($data);
+            $description['product_id'] = $res['id'];
+            $description['description'] = htmlspecialchars_decode($data['description']);
+            $description['type'] = 4;
+            StoreDescription::create($description);
+            return Json::successful('添加成功!');
+        }
+
+    }
+
+    /** 开启秒杀
+     * @param $id
+     * @return mixed|void
+     */
+    public function seckill($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        $product = ProductModel::get($id);
+        if (!$product) return Json::fail('数据不存在!');
+        $f = array();
+        $f[] = Form::input('title', '商品标题', $product->getData('store_name'));
+        $f[] = Form::hidden('product_id', $id);
+        $f[] = Form::input('info', '活动简介', $product->getData('store_info'))->type('textarea');
+        $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
+        $f[] = Form::select('temp_id', '运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
+            $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
+            $menus = [];
+            foreach ($list['data'] as $menu) {
+                $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
+            }
+            return $menus;
+        })->filterable(1)->col(12);
+        $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
+        $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')), json_decode($product->getData('slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px');
+        $f[] = Form::number('price', '积分价')->min(0)->col(12);
+        $f[] = Form::number('integral', '消耗积分')->min(0)->col(12);
+        $f[] = Form::number('ot_price', '原价', $product->getData('price'))->min(0)->col(12);
+        $f[] = Form::number('cost', '成本价', $product->getData('cost'))->min(0)->col(12);
+        $f[] = Form::number('stock', '库存', $product->getData('stock'))->min(0)->precision(0)->col(12);
+        $f[] = Form::number('sales', '销量', $product->getData('sales'))->min(0)->precision(0)->col(12);
+        $f[] = Form::number('sort', '排序', $product->getData('sort'))->col(12);
+        $f[] = Form::number('num', '单次购买商品个数', 1)->precision(0)->col(12);
+        $f[] = Form::number('give_integral', '赠送积分', $product->getData('give_integral'))->min(0)->precision(0)->col(12);
+        $f[] = Form::number('weight', '重量', 0)->min(0)->col(12);
+        $f[] = Form::number('volume', '体积', 0)->min(0)->col(12);
+//        $f[] = Form::number('deposit', '押金', 0)->min(0)->col(12);
+        $f[] = Form::radio('is_hot', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
+        $f[] = Form::radio('status', '活动状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
+        $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 显示编辑资源表单页.
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function edit($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        $product = StoreIntegralModel::get($id);
+//        $time = StoreSeckillTime::getSeckillTime($id);
+        if (!$product) return Json::fail('数据不存在!');
+        $f = array();
+        $f[] = Form::input('product_id', '产品ID', $product->getData('product_id'))->disabled(true);
+        $f[] = Form::input('title', '商品标题', $product->getData('title'));
+        $f[] = Form::input('info', '活动简介', $product->getData('info'))->type('textarea');
+        $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
+        $f[] = Form::select('temp_id', '运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
+            $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
+            $menus = [];
+            foreach ($list['data'] as $menu) {
+                $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
+            }
+            return $menus;
+        })->filterable(1)->col(12);
+        $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
+        $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')), json_decode($product->getData('images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
+        $f[] = Form::number('sort', '排序', $product->getData('sort'))->col(12);
+        $f[] = Form::hidden('stock', $product->getData('stock'));
+        $f[] = Form::hidden('price', $product->getData('price'));
+        $f[] = Form::hidden('integral', $product->getData('integral'));
+        $f[] = Form::hidden('ot_price', $product->getData('ot_price'));
+        $f[] = Form::hidden('sales', $product->getData('sales'));
+        $f[] = Form::number('num', '单次购买商品个数', $product->getData('num'))->precision(0)->col(12);
+        $f[] = Form::number('give_integral', '赠送积分', $product->getData('give_integral'))->min(0)->precision(0)->col(12);
+        $f[] = Form::radio('is_hot', '热门推荐', $product->getData('is_hot'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
+        $f[] = Form::hidden('status', $product->getData('status'));
+        $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save', compact('id')));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function delete($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        $product = StoreIntegralModel::get($id);
+        if (!$product) return Json::fail('数据不存在!');
+        if ($product['is_del']) return Json::fail('已删除!');
+        $data['is_del'] = 1;
+        if (!StoreIntegralModel::edit($data, $id))
+            return Json::fail(StoreIntegralModel::getErrorInfo('删除失败,请稍候再试!'));
+        else
+            return Json::successful('删除成功!');
+    }
+
+    public function edit_content($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        $seckill = StoreIntegralModel::get($id);
+        if (!$seckill) return Json::fail('数据不存在!');
+        $this->assign([
+            'content' => htmlspecialchars_decode(StoreDescription::getDescription($id, 4)),
+            'field' => 'description',
+            'action' => Url::buildUrl('change_field', ['id' => $id, 'field' => 'description'])
+        ]);
+        return $this->fetch('public/edit_content');
+    }
+
+    public function change_field($id)
+    {
+        if (!$id) return $this->failed('数据不存在');
+        $seckill = StoreIntegralModel::get($id);
+        if (!$seckill) return Json::fail('数据不存在!');
+        $data['description'] = request()->post('description');
+        StoreDescription::saveDescription($data['description'], $id, 4);
+        $res = StoreIntegralModel::edit($data, $id);
+        if ($res)
+            return Json::successful('添加成功');
+        else
+            return Json::fail('添加失败');
+    }
+
+    /**
+     * 属性页面
+     * @param $id
+     * @return mixed|void
+     */
+    public function attr($id)
+    {
+        if (!$id) return $this->failed('数据不存在!');
+        $result = StoreIntegralAttrResult::getResult($id);
+        $image = StoreIntegralModel::where('id', $id)->value('image');
+        $this->assign(compact('id', 'result', 'image'));
+        return $this->fetch();
+    }
+
+    /**
+     * 秒杀属性选择页面
+     * @param $id
+     * @return string|void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function attr_list($id)
+    {
+        if (!$id) return $this->failed('数据不存在!');
+        $seckillInfo = StoreIntegralModel::where('id', $id)->find();
+        $seckillResult = StoreProductAttrResult::where('product_id', $id)->where('type', 4)->value('result');
+        $productResult = StoreProductAttrResult::where('product_id', $seckillInfo['product_id'])->where('type', 0)->value('result');
+        if ($productResult) {
+            $attr = json_decode($productResult, true)['attr'];
+            $productAttr = $this->get_attr($attr, $seckillInfo['product_id'], 0);
+            $seckillAttr = $this->get_attr($attr, $id, 4);
+            foreach ($productAttr as $pk => $pv) {
+                foreach ($seckillAttr as $sv) {
+                    if ($pv['detail'] == $sv['detail']) {
+                        $productAttr[$pk] = $sv;
+                    }
+                }
+            }
+        } else {
+            if ($seckillResult) {
+                $attr = json_decode($seckillResult, true)['attr'];
+                $productAttr = $this->get_attr($attr, $id, 1);
+            } else {
+                $attr[0]['value'] = '默认';
+                $attr[0]['detailValue'] = '';
+                $attr[0]['attrHidden'] = '';
+                $attr[0]['detail'][0] = '默认';
+                $productAttr[0]['value1'] = '默认';
+                $productAttr[0]['detail'] = json_encode(['默认' => '默认']);
+                $productAttr[0]['pic'] = $seckillInfo['image'];
+                $productAttr[0]['price'] = $seckillInfo['price'];
+                $productAttr[0]['integral'] = $seckillInfo['integral'];
+                $productAttr[0]['cost'] = $seckillInfo['cost'];
+                $productAttr[0]['ot_price'] = $seckillInfo['ot_price'];
+                $productAttr[0]['stock'] = $seckillInfo['stock'];
+                $productAttr[0]['quota'] = 0;
+                $productAttr[0]['bar_code'] = $seckillInfo['bar_code'];
+                $productAttr[0]['weight'] = 0;
+                $productAttr[0]['volume'] = 0;
+                $productAttr[0]['deposit'] = 0;
+                $productAttr[0]['brokerage'] = 0;
+                $productAttr[0]['brokerage_two'] = 0;
+                $productAttr[0]['check'] = 0;
+            }
+        }
+        $attrs['attr'] = $attr;
+        $attrs['value'] = $productAttr;
+        $this->assign('attr', $attrs);
+        $this->assign('id', $id);
+        return $this->fetch();
+    }
+
+    /**
+     * 秒杀属性保存页面
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function save_attr()
+    {
+        $data = Util::postMore([
+            ['attr', []],
+            ['ids', []],
+            ['id', 0],
+        ]);
+        if (!$data['id']) return Json::fail('数据不存在!');
+        if (!$data['ids']) return Json::fail('你没有选择任何规格!');
+        $productId = StoreIntegralModel::where('id', $data['id'])->value('product_id');
+        $attr = json_decode(StoreProductAttrResult::where('product_id', $productId)->where('type', 0)->value('result'), true)['attr'];
+        foreach ($data['attr'] as $k => $v) {
+            if (in_array($k, $data['ids'])) {
+                $v['detail'] = json_decode(htmlspecialchars_decode($v['detail']), true);
+                $detail[$k] = $v;
+            }
+        }
+        if (min(array_column($detail, 'quota')) == 0) return Json::fail('限购不能为0');
+        $price = min(array_column($detail, 'price'));
+        $integral = min(array_column($detail, 'integral'));
+        $otPrice = min(array_column($detail, 'ot_price'));
+        $quota = array_sum(array_column($detail, 'quota'));
+        $stock = array_sum(array_column($detail, 'stock'));
+        $deposit = min(array_column($detail, 'deposit'));
+        if (!$attr) {
+            $attr[0]['value'] = '默认';
+            $attr[0]['detailValue'] = '';
+            $attr[0]['attrHidden'] = '';
+            $attr[0]['detail'][0] = '默认';
+        }
+        StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 4);
+        StoreIntegralModel::where('id', $data['id'])->update(['deposit' => $deposit, 'stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price, 'integral' => $integral, 'ot_price' => $otPrice]);
+        return Json::successful('修改成功!');
+    }
+
+    /**
+     * 生成属性
+     * @param int $id
+     */
+    public function is_format_attr($id = 0)
+    {
+        if (!$id) return Json::fail('商品不存在');
+        list($attr, $detail) = Util::postMore([
+            ['items', []],
+            ['attrs', []]
+        ], $this->request, true);
+        $product = StoreIntegralModel::get($id);
+        if (!$product) return Json::fail('商品不存在');
+        $attrFormat = attr_format($attr)[1];
+        if (count($detail)) {
+            foreach ($attrFormat as $k => $v) {
+                foreach ($detail as $kk => $vv) {
+                    if ($v['detail'] == $vv['detail']) {
+                        $attrFormat[$k]['price'] = $vv['price'];
+                        $attrFormat[$k]['integral'] = $vv['integral'];
+                        $attrFormat[$k]['sales'] = $vv['sales'];
+                        $attrFormat[$k]['pic'] = $vv['pic'];
+                        $attrFormat[$k]['check'] = false;
+                        break;
+                    } else {
+                        $attrFormat[$k]['price'] = '';
+                        $attrFormat[$k]['integral'] = '';
+                        $attrFormat[$k]['sales'] = '';
+                        $attrFormat[$k]['pic'] = $product['image'];
+                        $attrFormat[$k]['check'] = true;
+                    }
+                }
+            }
+        } else {
+            foreach ($attrFormat as $k => $v) {
+                $attrFormat[$k]['price'] = $product['price'];
+                $attrFormat[$k]['integral'] = $product['integral'];
+                $attrFormat[$k]['sales'] = $product['stock'];
+                $attrFormat[$k]['pic'] = $product['image'];
+                $attrFormat[$k]['check'] = false;
+            }
+        }
+        return Json::successful($attrFormat);
+    }
+
+
+    /**
+     * 修改秒杀商品状态
+     * @param $status
+     * @param int $id
+     */
+    public function set_seckill_status($status, $id = 0)
+    {
+        if (!$id) return Json::fail('参数错误');
+        $res = StoreProductAttrValue::where('product_id', $id)->where('type', 4)->find();
+        if (!$res) return Json::fail('请先配置规格');
+        $res = StoreIntegralModel::edit(['status' => $status], $id);
+        if ($res) return Json::successful('修改成功');
+        else return Json::fail('修改失败');
+    }
+
+    /**
+     * 秒杀获取商品列表
+     * @return string
+     * @throws \Exception
+     */
+    public function productList()
+    {
+        $cate = StoreCategory::getTierList(null, 4);
+        $this->assign('cate', $cate);
+        return $this->fetch();
+    }
+
+    /**
+     * 获取秒杀商品规格
+     * @param $attr
+     * @param $id
+     * @param $type
+     * @return array
+     */
+    public function get_attr($attr, $id, $type)
+    {
+        $value = attr_format($attr)[1];
+//        var_dump($value);
+//        var_dump($type);
+        $valueNew = [];
+        $count = 0;
+        foreach ($value as $key => $item) {
+            $detail = $item['detail'];
+//            sort($item['detail'], SORT_STRING);
+            $suk = implode(',', $item['detail']);
+            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,deposit,brokerage,brokerage_two,quota,integral', 'suk');
+            if (count($sukValue)) {
+                foreach (array_values($detail) as $k => $v) {
+                    $valueNew[$count]['value' . ($k + 1)] = $v;
+                }
+                $valueNew[$count]['detail'] = json_encode($detail);
+                $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
+                $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
+                $valueNew[$count]['integral'] = isset($sukValue[$suk]['integral']) ? floatval($sukValue[$suk]['integral']) : 0;
+                $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;
+                $valueNew[$count]['ot_price'] = isset($sukValue[$suk]['ot_price']) ? floatval($sukValue[$suk]['ot_price']) : 0;
+                $valueNew[$count]['stock'] = $sukValue[$suk]['stock'] ? intval($sukValue[$suk]['stock']) : 0;
+                $valueNew[$count]['quota'] = $sukValue[$suk]['quota'] ? intval($sukValue[$suk]['quota']) : 0;
+                $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
+                $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
+                $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
+                $valueNew[$count]['deposit'] = $sukValue[$suk]['deposit'] ?? 0;
+                $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
+                $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
+                $valueNew[$count]['check'] = $type != 0 ? 1 : 0;
+                $count++;
+            }
+        }
+        return $valueNew;
+    }
+}

+ 9 - 5
app/admin/controller/ump/StoreSeckill.php

@@ -7,7 +7,8 @@ use app\admin\model\store\{StoreDescription,
     StoreProductAttr,
     StoreProductAttrResult,
     StoreProduct as ProductModel,
-    StoreProductAttrValue};
+    StoreProductAttrValue
+};
 use crmeb\traits\CurdControllerTrait;
 use think\Exception;
 use think\exception\ErrorException;
@@ -182,7 +183,7 @@ class StoreSeckill extends AuthController
             StoreSeckillModel::edit($data, $id);
             return Json::successful('编辑成功!');
         } else {
-            if(StoreSeckillModel::checkSeckill($data['product_id'],$data['time_id'])) return Json::fail('该商品当前时间段已有秒杀活动');
+            if (StoreSeckillModel::checkSeckill($data['product_id'], $data['time_id'])) return Json::fail('该商品当前时间段已有秒杀活动');
             $data['add_time'] = time();
             $res = StoreSeckillModel::create($data);
             $description['product_id'] = $res['id'];
@@ -257,7 +258,7 @@ class StoreSeckill extends AuthController
 //        $time = StoreSeckillTime::getSeckillTime($id);
         if (!$product) return Json::fail('数据不存在!');
         $f = array();
-        $f[] = Form::input('product_id','产品ID', $product->getData('product_id'))->disabled(true);
+        $f[] = Form::input('product_id', '产品ID', $product->getData('product_id'))->disabled(true);
         $f[] = Form::input('title', '商品标题', $product->getData('title'));
         $f[] = Form::input('info', '秒杀活动简介', $product->getData('info'))->type('textarea');
         $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
@@ -399,6 +400,7 @@ class StoreSeckill extends AuthController
                 $productAttr[0]['bar_code'] = $seckillInfo['bar_code'];
                 $productAttr[0]['weight'] = 0;
                 $productAttr[0]['volume'] = 0;
+                $productAttr[0]['deposit'] = 0;
                 $productAttr[0]['brokerage'] = 0;
                 $productAttr[0]['brokerage_two'] = 0;
                 $productAttr[0]['check'] = 0;
@@ -439,6 +441,7 @@ class StoreSeckill extends AuthController
         $otPrice = min(array_column($detail, 'ot_price'));
         $quota = array_sum(array_column($detail, 'quota'));
         $stock = array_sum(array_column($detail, 'stock'));
+        $deposit = min(array_column($detail, 'deposit'));
         if (!$attr) {
             $attr[0]['value'] = '默认';
             $attr[0]['detailValue'] = '';
@@ -446,7 +449,7 @@ class StoreSeckill extends AuthController
             $attr[0]['detail'][0] = '默认';
         }
         StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 1);
-        StoreSeckillModel::where('id', $data['id'])->update(['stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price, 'ot_price' => $otPrice]);
+        StoreSeckillModel::where('id', $data['id'])->update(['deposit' => $deposit, 'stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price, 'ot_price' => $otPrice]);
         return Json::successful('修改成功!');
     }
 
@@ -566,7 +569,7 @@ class StoreSeckill extends AuthController
             $detail = $item['detail'];
 //            sort($item['detail'], SORT_STRING);
             $suk = implode(',', $item['detail']);
-            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
+            $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,deposit,brokerage,brokerage_two,quota', 'suk');
             if (count($sukValue)) {
                 foreach (array_values($detail) as $k => $v) {
                     $valueNew[$count]['value' . ($k + 1)] = $v;
@@ -581,6 +584,7 @@ class StoreSeckill extends AuthController
                 $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
                 $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
                 $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
+                $valueNew[$count]['deposit'] = $sukValue[$suk]['deposit'] ?? 0;
                 $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
                 $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
                 $valueNew[$count]['check'] = $type != 0 ? 1 : 0;

+ 14 - 4
app/admin/model/order/StoreOrder.php

@@ -51,10 +51,11 @@ class StoreOrder extends BaseModel
         $data['yt'] = self::statusByWhere(-2, new self())->where(['is_system_del' => 0])->count();
         $data['del'] = self::statusByWhere(-4, new self())->where(['is_system_del' => 0])->count();
         $data['write_off'] = self::statusByWhere(5, new self())->where(['is_system_del' => 0])->count();
-        $data['general'] = self::where(['pink_id' => 0, 'combination_id' => 0, 'seckill_id' => 0, 'bargain_id' => 0, 'is_system_del' => 0])->count();
+        $data['general'] = self::where(['pink_id' => 0, 'integral_id' => 0, 'combination_id' => 0, 'seckill_id' => 0, 'bargain_id' => 0, 'is_system_del' => 0])->count();
         $data['pink'] = self::where('pink_id|combination_id', '>', 0)->where('is_system_del', 0)->count();
         $data['seckill'] = self::where('seckill_id', '>', 0)->where('is_system_del', 0)->count();
         $data['bargain'] = self::where('bargain_id', '>', 0)->where('is_system_del', 0)->count();
+        $data['integral'] = self::where('integral_id', '>', 0)->where('is_system_del', 0)->count();
         return $data;
     }
 
@@ -113,6 +114,9 @@ class StoreOrder extends BaseModel
             } elseif ($item['bargain_id']) {
                 $item['pink_name'] = '[砍价订单]';
                 $item['color'] = '#12c5e9';
+            } elseif ($item['integral_id']) {
+                $item['pink_name'] = '[积分订单]';
+                $item['color'] = '#9fc5e9';
             } else {
                 if ($item['shipping_type'] == 1) {
                     $item['pink_name'] = '[普通订单]';
@@ -494,6 +498,9 @@ HTML;
             if ($where['combination_id'] == '砍价订单') {
                 $model = $model->where($aler . 'bargain_id', ">", 0);
             }
+            if ($where['combination_id'] == '积分订单') {
+                $model = $model->where($aler . 'integral_id', ">", 0);
+            }
         }
         if (isset($where['pay_type'])) {
             switch ($where['pay_type']) {
@@ -511,7 +518,7 @@ HTML;
         if (isset($where['type'])) {
             switch ($where['type']) {
                 case 1:
-                    $model = $model->where($aler . 'combination_id', 0)->where($aler . 'seckill_id', 0)->where($aler . 'bargain_id', 0);
+                    $model = $model->where($aler . 'integral_id', 0)->where($aler . 'combination_id', 0)->where($aler . 'seckill_id', 0)->where($aler . 'bargain_id', 0);
                     break;
                 case 2:
 //                    $model = $model->where($aler.'combination_id',">",0)->where($aler.'pink_id',">",0);
@@ -523,6 +530,9 @@ HTML;
                 case 4:
                     $model = $model->where($aler . 'bargain_id', ">", 0);
                     break;
+                case 5:
+                    $model = $model->where($aler . 'integral_id', ">", 0);
+                    break;
             }
         }
 
@@ -603,9 +613,9 @@ HTML;
                 'col' => 2
             ],
             [
-                'name' => '积分抵扣',
+                'name' => '使用积分',
                 'field' => '分',
-                'count' => $price['use_integral'] . '(抵扣金额:¥' . $price['deduction_price'] . ')',
+                'count' => $price['use_integral'],
                 'background_color' => 'layui-bg-blue',
                 'col' => 2
             ],

+ 9 - 5
app/admin/model/store/StoreProductAttr.php

@@ -31,7 +31,7 @@ class StoreProductAttr extends BaseModel
     }
 
 
-    public static function createProductAttr($attrList, $valueList, $productId, $type=0)
+    public static function createProductAttr($attrList, $valueList, $productId, $type = 0)
     {
         $result = ['attr' => $attrList, 'value' => $valueList];
         $attrValueList = [];
@@ -60,6 +60,8 @@ class StoreProductAttr extends BaseModel
                 return self::setErrorInfo('请填写正确的商品库存');
             if (!isset($value['cost']) || !is_numeric($value['cost']) || floatval($value['cost']) != $value['cost'])
                 return self::setErrorInfo('请填写正确的商品成本价格');
+            if (!isset($value['deposit']) || !is_numeric($value['deposit']) || floatval($value['deposit']) != $value['deposit'])
+                return self::setErrorInfo('请填写正确的商品押金');
             if (!isset($value['pic']) || empty($value['pic']))
                 return self::setErrorInfo('请上传商品图片');
             foreach ($value['detail'] as $attrName => $attrValue) {
@@ -89,10 +91,12 @@ class StoreProductAttr extends BaseModel
                 'product_id' => $productId,
                 'suk' => $suk,
                 'price' => $value['price'],
+                'integral' => $value['integral'] ?? 0,
+                'deposit' => $value['deposit'] ?? 0,
                 'cost' => $value['cost'],
                 'ot_price' => $value['ot_price'],
                 'stock' => $value['stock'],
-                'unique' => StoreProductAttrValue::where(['product_id'=>$productId,'suk'=>$suk,'type'=>$type])->value('unique') ? : '',
+                'unique' => StoreProductAttrValue::where(['product_id' => $productId, 'suk' => $suk, 'type' => $type])->value('unique') ?: '',
                 'image' => $value['pic'],
                 'bar_code' => $value['bar_code'] ?? '',
                 'weight' => $value['weight'] ?? 0,
@@ -107,7 +111,7 @@ class StoreProductAttr extends BaseModel
         if (!count($attrGroup) || !count($valueGroup)) return self::setErrorInfo('请设置至少一个属性!');
         $attrModel = new self;
         $attrValueModel = new StoreProductAttrValue;
-        if (!self::clearProductAttr($productId,$type)) return false;
+        if (!self::clearProductAttr($productId, $type)) return false;
         $res = false !== $attrModel->saveAll($attrGroup)
             && false !== $attrValueModel->saveAll($valueGroup)
             && false !== StoreProductAttrResult::setResult($result, $productId, $type);
@@ -117,11 +121,11 @@ class StoreProductAttr extends BaseModel
             return self::setErrorInfo('编辑商品属性失败!');
     }
 
-    public static function clearProductAttr($productId,$type=0)
+    public static function clearProductAttr($productId, $type = 0)
     {
         if (empty($productId) && $productId != 0) return self::setErrorInfo('商品不存在!');
         $res = false !== self::where('product_id', $productId)->where('type', $type)->delete()
-            && false !== StoreProductAttrValue::clearProductAttrValue($productId,$type);
+            && false !== StoreProductAttrValue::clearProductAttrValue($productId, $type);
         if (!$res)
             return self::setErrorInfo('编辑属性失败,清除旧属性失败!');
         else

+ 365 - 0
app/admin/model/ump/StoreIntegral.php

@@ -0,0 +1,365 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/11
+ */
+
+namespace app\admin\model\ump;
+
+use app\admin\model\order\StoreOrder;
+use app\admin\model\store\StoreProductRelation;
+use app\admin\model\system\SystemGroupData;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+use app\admin\model\store\StoreProduct;
+use crmeb\services\PHPExcelService;
+
+/**
+ * Class StoreSeckill
+ * @package app\admin\model\store
+ */
+class StoreIntegral extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'store_integral';
+
+    use ModelTrait;
+
+    public function getDescriptionAttr($value)
+    {
+        return htmlspecialchars_decode($value);
+    }
+
+    /**
+     * 秒杀产品过滤条件
+     * @param $model
+     * @param $type
+     * @return mixed
+     */
+    public static function setWhereType($model, $type)
+    {
+        switch ($type) {
+            case 1:
+                $data = ['status' => 0, 'is_del' => 0];
+                break;
+            case 2:
+                $data = ['status' => 1, 'is_del' => 0];
+                break;
+            case 3:
+                $data = ['status' => 1, 'is_del' => 0, 'stock' => 0];
+                break;
+            case 4:
+                $data = ['status' => 1, 'is_del' => 0, 'stock' => ['elt', 1]];
+                break;
+            case 5:
+                $data = ['is_del' => 1];
+                break;
+        }
+        if (isset($data)) $model = $model->where($data);
+        return $model;
+    }
+
+    /**
+     * 秒杀产品数量 图标展示
+     * @param $type
+     * @param $data
+     * @return array
+     */
+    public static function getChatrdata($type, $data)
+    {
+        $legdata = ['销量', '数量', '点赞', '收藏'];
+        $model = self::setWhereType(self::order('id desc'), $type);
+        $list = self::getModelTime(compact('data'), $model)
+            ->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,count(id) as count,sum(sales) as sales')
+            ->group('un_time')
+            ->distinct(true)
+            ->select()
+            ->each(function ($item) use ($data) {
+                $item['collect'] = self::getModelTime(compact('data'), new StoreProductRelation)->where('type', 'collect')->count();
+                $item['like'] = self::getModelTime(compact('data'), new StoreProductRelation())->where('type', 'like')->count();
+            })->toArray();
+        $chatrList = [];
+        $datetime = [];
+        $data_item = [];
+        $itemList = [0 => [], 1 => [], 2 => [], 3 => []];
+        foreach ($list as $item) {
+            $itemList[0][] = $item['sales'];
+            $itemList[1][] = $item['count'];
+            $itemList[2][] = $item['like'];
+            $itemList[3][] = $item['collect'];
+            array_push($datetime, $item['un_time']);
+        }
+        foreach ($legdata as $key => $leg) {
+            $data_item['name'] = $leg;
+            $data_item['type'] = 'line';
+            $data_item['data'] = $itemList[$key];
+            $chatrList[] = $data_item;
+            unset($data_item);
+        }
+        unset($leg);
+        $badge = self::getbadge(compact('data'), $type);
+        $count = self::setWhereType(self::getModelTime(compact('data'), new self()), $type)->count();
+        return compact('datetime', 'chatrList', 'legdata', 'badge', 'count');
+
+    }
+
+    /**
+     * 秒杀产品数量
+     * @param $where
+     * @param $type
+     * @return array
+     */
+    public static function getbadge($where, $type)
+    {
+        $StoreOrderModel = new StoreOrder();
+        $replenishment_num = sys_config('replenishment_num');
+        $replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
+        $stock1 = self::getModelTime($where, new self())->where('stock', '<', $replenishment_num)->column('stock', 'id');
+        $sum_stock = self::where('stock', '<', $replenishment_num)->column('stock', 'id');
+        $stk = [];
+        foreach ($stock1 as $item) {
+            $stk[] = $replenishment_num - $item;
+        }
+        $lack = array_sum($stk);
+        $sum = [];
+        foreach ($sum_stock as $val) {
+            $sum[] = $replenishment_num - $val;
+        }
+        return [
+            [
+                'name' => '商品种类',
+                'field' => '件',
+                'count' => self::setWhereType(new self(), $type)->where('add_time', '<', mktime(0, 0, 0, date('m'), date('d'), date('Y')))->count(),
+                'content' => '商品种类总数',
+                'background_color' => 'layui-bg-blue',
+                'sum' => self::count(),
+                'class' => 'fa fa fa-ioxhost',
+            ],
+            [
+                'name' => '新增商品',
+                'field' => '件',
+                'count' => self::setWhereType(self::getModelTime($where, new self), $type)->sum('stock'),
+                'content' => '新增商品总数',
+                'background_color' => 'layui-bg-cyan',
+                'sum' => self::where('status', 1)->sum('stock'),
+                'class' => 'fa fa-line-chart',
+            ],
+            [
+                'name' => '秒杀成功商品件数',
+                'field' => '件',
+                'count' => self::getModelTime($where, $StoreOrderModel)->where('seckill_id', '<>', 0)->sum('total_num'),
+                'content' => '秒杀成功商品总件数',
+                'background_color' => 'layui-bg-green',
+                'sum' => $StoreOrderModel->where('seckill_id', '<>', 0)->sum('total_num'),
+                'class' => 'fa fa-bar-chart',
+            ],
+            [
+                'name' => '缺货商品',
+                'field' => '件',
+                'count' => $lack,
+                'content' => '总商品数量',
+                'background_color' => 'layui-bg-orange',
+                'sum' => array_sum($sum),
+                'class' => 'fa fa-cube',
+            ],
+        ];
+    }
+
+    /**
+     * 销量排行 top 10
+     * layui-bg-red 红 layui-bg-orange 黄 layui-bg-green 绿 layui-bg-blue 蓝 layui-bg-cyan 黑
+     */
+    public static function getMaxList($where)
+    {
+        $classs = ['layui-bg-red', 'layui-bg-orange', 'layui-bg-green', 'layui-bg-blue', 'layui-bg-cyan'];
+        $model = StoreOrder::alias('a')->join('store_seckill b', 'b.id=a.seckill_id')->where('a.paid', 1);
+        $list = self::getModelTime($where, $model, 'a.add_time')->group('a.seckill_id')->order('p_count desc')->limit(10)
+            ->field(['count(a.seckill_id) as p_count', 'b.title as store_name', 'sum(b.price) as sum_price'])->select();
+        if (count($list)) $list = $list->toArray();
+        $maxList = [];
+        $sum_count = 0;
+        $sum_price = 0;
+        foreach ($list as $item) {
+            $sum_count += $item['p_count'];
+            $sum_price = bcadd($sum_price, $item['sum_price'], 2);
+        }
+        unset($item);
+        foreach ($list as $key => &$item) {
+            $item['w'] = bcdiv($item['p_count'], $sum_count, 2) * 100;
+            $item['class'] = isset($classs[$key]) ? $classs[$key] : (isset($classs[$key - count($classs)]) ? $classs[$key - count($classs)] : '');
+            $item['store_name'] = self::getSubstrUTf8($item['store_name']);
+        }
+        $maxList['sum_count'] = $sum_count;
+        $maxList['sum_price'] = $sum_price;
+        $maxList['list'] = $list;
+        return $maxList;
+    }
+
+    /**
+     * 获取秒杀利润
+     * @param $where
+     * @return array
+     */
+    public static function ProfityTop10($where)
+    {
+        $classs = ['layui-bg-red', 'layui-bg-orange', 'layui-bg-green', 'layui-bg-blue', 'layui-bg-cyan'];
+        $model = StoreOrder::alias('a')->join('store_seckill b', 'b.id = a.seckill_id')->where('a.paid', 1);
+        $list = self::getModelTime($where, $model, 'a.add_time')->group('a.seckill_id')->order('profity desc')->limit(10)
+            ->field(['count(a.seckill_id) as p_count', 'b.title as store_name', 'sum(b.price) as sum_price', '(b.price-b.cost) as profity'])
+            ->select();
+        if (count($list)) $list = $list->toArray();
+        $maxList = [];
+        $sum_count = 0;
+        $sum_price = 0;
+        foreach ($list as $item) {
+            $sum_count += $item['p_count'];
+            $sum_price = bcadd($sum_price, $item['sum_price'], 2);
+        }
+        foreach ($list as $key => &$item) {
+            $item['w'] = bcdiv($item['sum_price'], $sum_price, 2) * 100;
+            $item['class'] = isset($classs[$key]) ? $classs[$key] : (isset($classs[$key - count($classs)]) ? $classs[$key - count($classs)] : '');
+            $item['store_name'] = self::getSubstrUTf8($item['store_name'], 30);
+        }
+        $maxList['sum_count'] = $sum_count;
+        $maxList['sum_price'] = $sum_price;
+        $maxList['list'] = $list;
+        return $maxList;
+    }
+
+    /**
+     * 获取秒杀缺货
+     * @param $where
+     * @return array
+     */
+    public static function getLackList($where)
+    {
+        $replenishment_num = sys_config('replenishment_num');
+        $replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
+        $list = self::where('stock', '<', $replenishment_num)->field(['id', 'title as store_name', 'stock', 'price'])->page((int)$where['page'], (int)$where['limit'])->order('stock asc')->select();
+        if (count($list)) $list = $list->toArray();
+        $count = self::where('stock', '<', $replenishment_num)->count();
+        return ['count' => $count, 'data' => $list];
+    }
+
+    /**
+     * 秒杀产品评价
+     * @param array $where
+     * @return array
+     */
+    public static function getNegativeList($where = array())
+    {
+        $replenishment_num = 3;
+        return [];
+    }
+
+    /**
+     * 秒杀产品退货
+     * @param array $where
+     * @return mixed
+     */
+    public static function getBargainRefundList($where = array())
+    {
+        $model = StoreOrder::alias('a')->join('store_seckill b', 'b.id=a.seckill_id');
+        $list = self::getModelTime($where, $model, 'a.add_time')->where('a.refund_status', '<>', 0)->group('a.seckill_id')->order('count desc')->page((int)$where['page'], (int)$where['limit'])
+            ->field(['count(a.seckill_id) as count', 'b.title as store_name', 'sum(b.price) as sum_price'])->select();
+        if (count($list)) $list = $list->toArray();
+        return $list;
+    }
+
+    /**
+     * @param $where
+     * @return array
+     */
+    public static function systemPage($where)
+    {
+        $model = new self;
+        $model = $model->alias('s');
+        if ($where['status'] != '') $model = $model->where('s.status', $where['status']);
+        if ($where['store_name'] != '') $model = $model->where('s.title|s.id', 'LIKE', "%$where[store_name]%");
+        $model = $model->page(bcmul($where['page'], $where['limit'], 0), $where['limit']);
+        $model = $model->order('s.id desc');
+        $model = $model->where('s.is_del', 0);
+        return self::page($model, function ($item) {
+            $item['store_name'] = StoreProduct::where('id', $item['product_id'])->value('store_name');
+        }, $where, $where['limit']);
+    }
+
+    public static function SaveExcel($where)
+    {
+        $model = new self;
+        if ($where['status'] != '') $model = $model->where('status', $where['status']);
+        if ($where['store_name'] != '') $model = $model->where('title|id', 'LIKE', "%$where[store_name]%");
+        $list = $model->order('id desc')->where('is_del', 0)->select();
+        count($list) && $list = $list->toArray();
+        $excel = [];
+        foreach ($list as $item) {
+            $item['store_name'] = StoreProduct::where('id', $item['product_id'])->value('store_name');
+            $excel[] = [
+                $item['id'],
+                $item['title'],
+                $item['info'],
+                $item['ot_price'],
+                $item['price'],
+                $item['integral'],
+                $item['stock'],
+                $item['status'] ? '开启' : '关闭',
+            ];
+        }
+        PHPExcelService::setExcelHeader(['编号', '活动标题', '活动简介', '原价', '积分价', '消耗积分', '库存', '状态'])
+            ->setExcelTile('积分产品导出', ' ', ' 生成时间:' . date('Y-m-d H:i:s', time()))
+            ->setExcelContent($excel)
+            ->ExcelSave();
+    }
+
+    /**
+     * 获取秒杀产品id
+     * @return array
+     */
+    public static function getSeckillIdAll()
+    {
+        return self::where('is_del', 0)->column('id', 'id');
+    }
+
+    /**
+     * 获取秒杀的所有产品
+     * @return int|string
+     */
+    public static function getSeckillCount()
+    {
+        return self::where('is_del', 0)->count();
+    }
+
+    /**
+     * TODO 获取某个字段值
+     * @param $id
+     * @param string $field
+     * @return mixed
+     */
+    public static function getSeckillField($id, $field = 'title')
+    {
+        return self::where('id', $id)->value($field);
+    }
+
+    /**
+     * 判断产品当前时间段是否有秒杀活动
+     * @param $product_id
+     * @param $time_id
+     * @return array|null|\think\Model
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function checkSeckill($product_id, $time_id)
+    {
+        return self::where('product_id', $product_id)->where('time_id', $time_id)->where('is_del', 0)->find();
+    }
+}

+ 51 - 0
app/admin/model/ump/StoreIntegralAttrResult.php

@@ -0,0 +1,51 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/12/09
+ */
+
+namespace app\admin\model\ump;
+
+use crmeb\basic\BaseModel;
+use crmeb\traits\ModelTrait;
+
+class StoreIntegralAttrResult extends BaseModel
+{
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'store_integral_attr_result';
+
+    use ModelTrait;
+
+    protected $insert = ['change_time'];
+
+    protected static function setChangeTimeAttr($value)
+    {
+        return time();
+    }
+
+    protected static function setResultAttr($value)
+    {
+        return is_array($value) ? json_encode($value) : $value;
+    }
+
+    public static function setResult($result,$product_id)
+    {
+        $result = self::setResultAttr($result);
+        $change_time = self::setChangeTimeAttr(0);
+        return self::insert(compact('product_id','result','change_time'),true);
+    }
+
+    public static function getResult($productId)
+    {
+        return json_decode(self::where('product_id',$productId)->value('result'),true) ?: [];
+    }
+
+    public static function clearResult($productId)
+    {
+        return self::del($productId);
+    }
+
+}

+ 53 - 0
app/admin/model/ump/StoreIntegralAttrValue.php

@@ -0,0 +1,53 @@
+<?php
+/**
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/12/08
+ */
+
+namespace app\admin\model\ump;
+
+use crmeb\basic\BaseModel;
+use crmeb\traits\ModelTrait;
+
+class StoreIntegralAttrValue extends BaseModel
+{
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'store_integral_attr_value';
+
+    use ModelTrait;
+
+    protected $insert = ['unique'];
+
+    protected function setSukAttr($value)
+    {
+        return is_array($value) ? implode(',',$value) : $value;
+    }
+
+    protected function setUniqueAttr($value,$data)
+    {
+        if(is_array($data['suk'])) $data['suk'] = $this->setSukAttr($data['suk']);
+        return self::uniqueId($data['product_id'].$data['suk'].uniqid(true));
+    }
+
+    public static function decProductAttrStock($productId,$unique,$num)
+    {
+        return false !== self::where('product_id',$productId)->where('unique',$unique)
+            ->dec('stock',$num)->inc('sales',$num)->update();
+    }
+
+
+    public static function uniqueId($key)
+    {
+        return substr(md5($key),12,8);
+    }
+
+    public static function clearProductAttrValue($productId)
+    {
+        return self::where('product_id',$productId)->delete();
+    }
+
+
+}

+ 75 - 30
app/admin/view/order/store_order/index.php

@@ -4,23 +4,27 @@
 {/block}
 {block name="content"}
 <style>
-    .btn-outline{
-        border:none;
+    .btn-outline {
+        border: none;
     }
-    .btn-outline:hover{
+
+    .btn-outline:hover {
         background-color: #0e9aef;
         color: #fff;
     }
+
     .layui-form-item .layui-btn {
         margin-top: 5px;
         margin-right: 10px;
     }
-    .layui-btn-primary{
+
+    .layui-btn-primary {
         margin-right: 10px;
-        margin-left: 0!important;
+        margin-left: 0 !important;
     }
-    label{
-        margin-bottom: 0!important;
+
+    label {
+        margin-bottom: 0 !important;
         margin-top: 4px;
     }
 </style>
@@ -314,7 +318,8 @@
                                     <i class="fa fa-history"></i> 立即退款
                                 </a>
                             </li>
-                            {{# }else if(d.use_integral > 0 && d.use_integral >= d.back_integral){ }}
+                            {{# } ;}}
+                            {{# if(d.use_integral > 0 && d.use_integral >= d.back_integral){ }}
                             <li>
                                 <a href="javascript:void(0);"
                                    onclick="$eb.createModalFrame('退积分','{:Url('integral_back')}?id={{d.id}}')">
@@ -322,6 +327,14 @@
                                 </a>
                             </li>
                             {{# } ;}}
+                            {{# if(parseFloat(d.deposit) > parseFloat(d.deposit_back)){ }}
+                            <li>
+                                <a href="javascript:void(0);"
+                                   onclick="$eb.createModalFrame('退押金','{:Url('refund_deposit_y')}?id={{d.id}}')">
+                                    <i class="fa fa-history"></i> 退押金
+                                </a>
+                            </li>
+                            {{# } }}
                             <li>
                                 <a href="javascript:void(0);"
                                    onclick="$eb.createModalFrame('订单记录','{:Url('order_status')}?oid={{d.id}}')">
@@ -349,13 +362,20 @@
                                     <i class="fa fa-motorcycle"></i> 去送货
                                 </a>
                             </li>
-                            {{# if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) >
-                            parseFloat(d.back_integral)){ }}
+                            {{# if(parseFloat(d.deposit) > parseFloat(d.deposit_back)){ }}
+                            <li>
+                                <a href="javascript:void(0);"
+                                   onclick="$eb.createModalFrame('退押金','{:Url('refund_deposit_y')}?id={{d.id}}')">
+                                    <i class="fa fa-history"></i> 退押金
+                                </a>
+                            </li>
+                            {{# } }}
                             <li>
                                 <a lay-event='marke' href="javascript:void(0);">
                                     <i class="fa fa-paste"></i> 订单备注
                                 </a>
                             </li>
+                            {{# if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) > parseFloat(d.back_integral)){ }}
                             <li>
                                 <a href="javascript:void(0);"
                                    onclick="$eb.createModalFrame('退积分','{:Url('integral_back')}?id={{d.id}}',{w:400,h:300})">
@@ -420,8 +440,15 @@
                                     <i class="fa fa-history"></i> 立即退款
                                 </a>
                             </li>
-                            {{# }else if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) >
-                            parseFloat(d.back_integral)){ }}
+                            {{# if(parseFloat(d.deposit) > parseFloat(d.deposit_back)){ }}
+                            <li>
+                                <a href="javascript:void(0);"
+                                   onclick="$eb.createModalFrame('退押金','{:Url('refund_deposit_y')}?id={{d.id}}')">
+                                    <i class="fa fa-history"></i> 退押金
+                                </a>
+                            </li>
+                            {{# } }}
+                            {{# }else if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) > parseFloat(d.back_integral)){ }}
                             <li>
                                 <a href="javascript:void(0);"
                                    onclick="$eb.createModalFrame('退积分','{:Url('integral_back')}?id={{d.id}}')">
@@ -463,8 +490,15 @@
                                 </a>
                             </li>
                             {{# };}}
-                            {{# if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) >
-                            parseFloat(d.back_integral)){ }}
+                            {{# if(parseFloat(d.deposit) > parseFloat(d.deposit_back)){ }}
+                            <li>
+                                <a href="javascript:void(0);"
+                                   onclick="$eb.createModalFrame('退押金','{:Url('refund_deposit_y')}?id={{d.id}}')">
+                                    <i class="fa fa-history"></i> 退押金
+                                </a>
+                            </li>
+                            {{# } }}
+                            {{# if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) > parseFloat(d.back_integral)){ }}
                             <li>
                                 <a href="javascript:void(0);"
                                    onclick="$eb.createModalFrame('退积分','{:Url('integral_back')}?id={{d.id}}')">
@@ -483,11 +517,11 @@
                         <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span
                                     class="caret"></span></button>
                         <ul class="layui-nav-child layui-anim layui-anim-upbit">
-                            <li>
-                                <a href="javascript:void(0);" lay-event='order_print'>
-                                    <i class="fa fa-file-text"></i> 打印订单
-                                </a>
-                            </li>
+<!--                            <li>-->
+<!--                                <a href="javascript:void(0);" lay-event='order_print'>-->
+<!--                                    <i class="fa fa-file-text"></i> 打印订单-->
+<!--                                </a>-->
+<!--                            </li>-->
                             <li>
                                 <a href="javascript:void(0);" lay-event='order_info'>
                                     <i class="fa fa-file-text"></i> 订单详情
@@ -506,8 +540,15 @@
                                 </a>
                             </li>
                             {{# } }}
-                            {{# if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) >=
-                            parseFloat(d.back_integral)){ }}
+                            {{# if(parseFloat(d.deposit) > parseFloat(d.deposit_back)){ }}
+                            <li>
+                                <a href="javascript:void(0);"
+                                   onclick="$eb.createModalFrame('退押金','{:Url('refund_deposit_y')}?id={{d.id}}')">
+                                    <i class="fa fa-history"></i> 退押金
+                                </a>
+                            </li>
+                            {{# } }}
+                            {{# if(parseFloat(d.use_integral) > 0 && parseFloat(d.use_integral) >= parseFloat(d.back_integral)){ }}
                             <li>
                                 <a href="javascript:void(0);"
                                    onclick="$eb.createModalFrame('退积分','{:Url('integral_back')}?id={{d.id}}')">
@@ -537,13 +578,16 @@
     layList.tableList('List', "{:Url('order_list',['real_name'=>$real_name])}", function () {
         return [
             {type: 'checkbox'},
-            {field: 'order_id', title: '订单号', sort: true, event: 'order_id', width: '14%', templet: '#order_id'},
-            {field: 'nickname', title: '用户信息', templet: '#userinfo', width: '10%', align: 'center'},
-            {field: 'spread_uid', title: '推荐人信息', templet: '#spread_uid', width: '10%', align: 'center'},
+            {field: 'order_id', title: '订单号', sort: true, event: 'order_id', width: '12%', templet: '#order_id'},
+            {field: 'nickname', title: '用户信息', templet: '#userinfo', width: '8%', align: 'center'},
+            {field: 'spread_uid', title: '推荐人信息', templet: '#spread_uid', width: '8%', align: 'center'},
             {field: 'info', title: '商品信息', templet: "#info", height: 'full-20'},
-            {field: 'pay_price', title: '实际支付', width: '8%', align: 'center'},
-            {field: 'paid', title: '支付状态', templet: '#paid', width: '8%', align: 'center'},
-            {field: 'status', title: '订单状态', templet: '#status', width: '8%', align: 'center'},
+            {field: 'pay_price', title: '支付金额', width: '6%', align: 'center'},
+            {field: 'deposit', title: '支付押金', width: '6%', align: 'center'},
+            {field: 'deposit_back', title: '已退押金', width: '6%', align: 'center'},
+            {field: 'use_integral', title: '使用积分', width: '6%', align: 'center'},
+            {field: 'paid', title: '支付状态', templet: '#paid', width: '6%', align: 'center'},
+            {field: 'status', title: '订单状态', templet: '#status', width: '6%', align: 'center'},
             {field: 'add_time', title: '下单时间', width: '10%', sort: true, align: 'center'},
             {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '10%'},
         ];
@@ -693,8 +737,8 @@
     }
 
     var real_name = '<?=$real_name?>';
-    var orderCount =<?=json_encode($orderCount)?>, payTypeCount =<?=json_encode($payTypeCount)?>,
-        status =<?=$status ? $status : "''"?>;
+    var orderCount = <?=json_encode($orderCount)?>, payTypeCount = <?=json_encode($payTypeCount)?>,
+        status = <?=$status ? $status : "''"?>;
     require(['vue'], function (Vue) {
         new Vue({
             el: "#app",
@@ -711,7 +755,8 @@
                     {name: '普通订单', value: 1, count: orderCount.general},
                     {name: '拼团订单', value: 2, count: orderCount.pink},
                     {name: '秒杀订单', value: 3, count: orderCount.seckill},
-                    {name: '砍价订单', value: 4, count: orderCount.bargain},
+                    {name: '积分订单', value: 5, count: orderCount.integral},
+                    // {name: '砍价订单', value: 4, count: orderCount.bargain},
                 ],
                 orderStatus: [
                     {name: '全部', value: ''},

+ 22 - 0
app/admin/view/store/store_product/create.php

@@ -349,6 +349,7 @@
                                                             <th>产品编号</th>
                                                             <th>重量(KG)</th>
                                                             <th>体积(m³)</th>
+                                                            <th>押金</th>
                                                         </tr>
                                                         </thead>
                                                         <tr>
@@ -379,6 +380,8 @@
                                                                        class="layui-input"></td>
                                                             <td><input type="text" v-model="formData.attr.volume"
                                                                        class="layui-input"></td>
+                                                            <td><input type="text" v-model="formData.attr.deposit"
+                                                                       class="layui-input"></td>
                                                         </tr>
                                                     </table>
                                                 </div>
@@ -492,6 +495,7 @@
                                                                 <th>产品编号</th>
                                                                 <th>重量(KG)</th>
                                                                 <th>体积(m³)</th>
+                                                                <th>押金</th>
                                                                 <th width="15%" style="text-align: center;">操作</th>
                                                             </tr>
                                                             </thead>
@@ -532,6 +536,10 @@
                                                                     <input type="text" v-model="batchAttr.volume"
                                                                            class="layui-input">
                                                                 </td>
+                                                                <td>
+                                                                    <input type="text" v-model="batchAttr.deposit"
+                                                                           class="layui-input">
+                                                                </td>
                                                                 <td style="text-align: center;">
                                                                     <button class="layui-btn layui-btn-sm" type="button"
                                                                             @click="batchAdd">批量修改
@@ -597,6 +605,10 @@
                                                                     <input type="number" v-model="item.volume"
                                                                            class="layui-input">
                                                                 </td>
+                                                                <td>
+                                                                    <input type="number" v-model="item.deposit"
+                                                                           class="layui-input">
+                                                                </td>
                                                                 <td>
                                                                     <button class="layui-btn layui-btn-sm" type="button"
                                                                             @click="deleteAttrs(index)">删除
@@ -744,6 +756,7 @@
                                                             <th>产品编号</th>
                                                             <th>重量</th>
                                                             <th>体积</th>
+                                                            <th>押金</th>
                                                             <th>一级返佣</th>
                                                             <th>二级返佣</th>
                                                         </tr>
@@ -763,6 +776,7 @@
                                                             <td>{{formData.attr.bar_code}}</td>
                                                             <td>{{formData.attr.weight}}</td>
                                                             <td>{{formData.attr.volume}}</td>
+                                                            <td>{{formData.attr.deposit}}</td>
                                                             <td><input type="text" v-model="formData.attr.brokerage"
                                                                        class="layui-input"></td>
                                                             <td><input type="text" v-model="formData.attr.brokerage_two"
@@ -805,6 +819,7 @@
                                                             <td>{{item.bar_code}}</td>
                                                             <td>{{item.weight}}</td>
                                                             <td>{{item.volume}}</td>
+                                                            <td>{{item.deposit}}</td>
                                                             <td>
                                                                 <input type="number" v-model="item.brokerage"
                                                                        class="layui-input">
@@ -1006,6 +1021,7 @@
                     bar_code: '',
                     weight: 0,
                     volume: 0,
+                    deposit: 0,
                     brokerage: 0,
                     brokerage_two: 0,
                 },
@@ -1043,6 +1059,7 @@
                 bar_code: '',
                 weight: 0,
                 volume: 0,
+                deposit: 0,
             },
             //多属性header头
             formHeader: [],
@@ -1154,6 +1171,7 @@
                     bar_code: '',
                     weight: 0,
                     volume: 0,
+                    deposit: 0,
                 });
             },
             /**
@@ -1186,6 +1204,9 @@
                     if (that.batchAttr.volume > 0) {
                         item.volume = that.batchAttr.volume;
                     }
+                    if (that.batchAttr.deposit > 0) {
+                        item.deposit = that.batchAttr.deposit;
+                    }
                     return item;
                 }));
 
@@ -1589,6 +1610,7 @@
                         stock: that.formData.attr.stock,
                         bar_code: that.formData.attr.bar_code,
                         volume: that.formData.attr.volume,
+                        deposit: that.formData.attr.deposit,
                         weight: that.formData.attr.weight,
                         brokerage: that.formData.attr.brokerage,
                         brokerage_two: that.formData.attr.brokerage_two,

+ 1 - 0
app/admin/view/ump/store_bargain/attr_list.php

@@ -38,6 +38,7 @@
                     <th>商品编号</th>
                     <th>重量</th>
                     <th>体积</th>
+                    <th>押金</th>
                     <th>选择</th>
                 </tr>
                 </thead>

+ 1 - 0
app/admin/view/ump/store_combination/attr_list.php

@@ -37,6 +37,7 @@
                     <th>商品编号</th>
                     <th>重量</th>
                     <th>体积</th>
+                    <th>押金</th>
                     <th>选择</th>
                 </tr>
                 </thead>

+ 371 - 0
app/admin/view/ump/store_integral/attr.php

@@ -0,0 +1,371 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    {include file="public/head"}
+    <title>{$title|default=''}</title>
+    <style>
+        .demo-upload{
+            display: block;
+            height: 33px;
+            text-align: center;
+            border: 1px solid transparent;
+            border-radius: 4px;
+            overflow: hidden;
+            background: #fff;
+            position: relative;
+            box-shadow: 0 1px 1px rgba(0,0,0,.2);
+            margin-right: 4px;
+        }
+        .demo-upload img{
+            width: 100%;
+            height: 100%;
+            display: block;
+        }
+        .demo-upload-cover{
+            display: none;
+            position: absolute;
+            top: 0;
+            bottom: 0;
+            left: 0;
+            right: 0;
+            background: rgba(0,0,0,.6);
+        }
+        .demo-upload:hover .demo-upload-cover{
+            display: block;
+        }
+        .demo-upload-cover i{
+            color: #fff;
+            font-size: 20px;
+            cursor: pointer;
+            margin: 0 2px;
+        }
+        .check{color: #f00}
+    </style>
+</head>
+<body>
+<div id="store-attr" class="mp-form" v-cloak="">
+    <i-Form :label-width="80" style="width: 100%" v-show="hidden == false">
+        <Form-Item>
+            <Row>
+                <i-Col span="5">
+                    <i-Button type="dashed" long @click="hiddenBool" icon="plus-round">添加新规则</i-Button>
+                </i-Col>
+            </Row>
+        </Form-Item>
+    </i-Form>
+    <i-Form :label-width="80" style="width: 100%" v-show="hidden == true">
+        <Form-Item
+                :label="'规则名称:'">
+            <Row>
+                <i-Col style="position: relative;margin-right: 6px"  span="5"
+                       v-for="(item, index) in items"
+                       :key="index">
+                    <i-Input type="text" v-model="item.value" placeholder="设置名称"></i-Input>
+                    <i-Button style="position: absolute;top:0;right:0;margin-top:1px;border: none;font-size: 8px;line-height: 1.8" type="ghost" @click="handleRemove(index)" v-show="item.attrHidden == true"><Icon type="close-round" /></i-Button>
+                    <i-Button style="position: absolute;top:0;right:0;margin-top:1px;border: none;font-size: 8px;line-height: 1.8" type="ghost" @click="attrHiddenBool(item)" v-show="item.attrHidden == false"><Icon type="checkmark-round"></Icon></i-Button>
+                </i-Col>
+                <i-Col span="5">
+                    <i-Button type="dashed" long @click="handleAdd" icon="plus-round">添加新规则</i-Button>
+                </i-Col>
+            </Row>
+        </Form-Item>
+        <Form-Item v-show="item.attrHidden == true"
+                   v-for="(item, index) in items"
+                   :key="index"
+                   :label="''+item.value+':'" >
+            <Row>
+                <i-Col span="3"
+                       v-for="(attr,k) in item.detail"
+                       :key="attr"
+                       :name="attr">
+                    <Tag type="border" closable color="blue" @on-close="attrRemove(item,k)">{{ attr }}</Tag>
+                </i-Col>
+                <i-Col span="5">
+                    <i-Input type="text" v-model="item.detailValue" placeholder="设置属性"></i-Input>
+                </i-Col>
+                <i-Col span="5">
+                    <i-Button type="primary" style="margin-left: 6px" @click="attrAdd(item)">添加</i-Button>
+                </i-Col>
+            </Row>
+        </Form-Item>
+        <Form-Item v-show="hidden == true" style="width: 100%;">
+            <Row style="margin: 0 88px 0 20px">
+                <i-Col span="24">
+                    <i-Button type="primary" long @click="addGoods(true)">生成</i-Button>
+                </i-Col>
+            </Row>
+        </Form-Item>
+
+        <template v-if="items[0].value!='' && items[0].detail.length>0 && attrs.length">
+            <template v-for="(attr,index) in attrs">
+                <Form-Item>
+                    <Row>
+                        <template v-for="(item,index) in attr.detail">
+                            <i-Col span="3" style="margin-right: 3px">
+                                {{index}}:{{item}}
+                            </i-Col>
+                        </template>
+                        <i-Col span="5" style="margin-right: 3px">
+                            <span :class="attr.check ? 'check':''">金额:</span>&nbsp;&nbsp;<i-Input placeholder="请输入金额" v-model="attr.price" style="width: 68%"
+                                        :number="true"></i-Input>
+                        </i-Col>
+                        <i-Col span="5" style="margin-right: 3px">
+                            <span :class="attr.check ? 'check':''">库存:</span>&nbsp;&nbsp;<i-Input placeholder="请输入库存" v-model="attr.sales" style="width: 68%"
+                                        :number="true"></i-Input>
+                        </i-Col>
+                        <i-Col span="2" offset="1" style="margin-right: 3px">
+                            <div class="demo-upload">
+                                <img :src="attr.pic">
+                                <div class="demo-upload-cover">
+                                    <Icon type="ios-eye-outline" @click.native="openPic(attr.pic)" ></Icon>
+                                    <Upload
+                                            :show-upload-list="false"
+                                            :on-success="uploadSuccess(attr)"
+                                            :on-error="uploadError"
+                                            :format="['jpg','jpeg','png']"
+                                            :max-size="2048"
+                                            accept="image/*"
+                                            :on-format-error="uploadFormatError"
+                                            action="{:Url('upload')}"
+                                            style="display: inline-block"
+                                            :goods="attr"
+                                    >
+                                        <Icon type="ios-cloud-upload-outline"></Icon>
+                                    </Upload>
+
+                                </div>
+                            </div>
+                        </i-Col>
+                        <i-Col span="2" style="margin-right: 3px">
+                            <i-Button type="ghost" @click="removeGoods(index)">删除</i-Button>
+                        </i-Col>
+                    </Row>
+                </Form-Item>
+            </template>
+            <Form-Item>
+                <Row>
+                    <!--                    <i-Col span="10">-->
+                    <!--                        <i-Button type="dashed" long @click="addGoods" icon="plus-round">添加新商品</i-Button>-->
+                    <!--                    </i-Col>-->
+                    <i-Col span="2" offset="2">
+                        <i-Button type="primary" @click="submit">提交</i-Button>
+                    </i-Col>
+                    <i-Col span="2" offset="1">
+                        <i-Button type="error" @click="clear">清空所有属性</i-Button>
+                    </i-Col>
+                </Row>
+            </Form-Item>
+        </template>
+    </i-Form>
+    <Spin fix v-show="submiting == true">保存中...</Spin>
+</div>
+<script>
+    var _vm ;
+    mpFrame.start(function(Vue){
+        new Vue({
+            data () {
+                return {
+                    hidden:false,
+                    submiting :false,
+                    items: <?php echo $result && isset($result['attr']) && !empty($result['attr']) ? json_encode($result['attr']) : 'false'; ?> || [
+                    {
+                        value: '',
+                        detailValue:'',
+                        attrHidden:false,
+                        detail:[]
+                    }
+                ],
+                    attrs:<?php echo $result && isset($result['value']) && !empty($result['value']) ? json_encode($result['value']) : '[]'; ?>
+            }
+            },
+            watch:{
+                items:{
+                    handler:function(){
+//                        this.attrs = [];
+                    },
+                    deep:true
+                }
+            },
+            methods: {
+                attrHiddenBool(item){
+                    if(item.value == ''){
+                        $eb.message('error','请填写规则名称');
+                    }else{
+                        item.attrHidden = true;
+                    }
+                },
+                hiddenBool(){
+                    this.hidden = true;
+                },
+                handleAdd () {
+                    if(!this.checkAttr())return ;
+                    this.items.push({
+                        value: '',
+                        detailValue:'',
+                        attrHidden:false,
+                        detail:[]
+                    });
+                },
+                checkAttr(){
+                    var bool = true;
+                    this.items.map(function(item){
+                        if(!bool) return;
+                        if(!item.value){
+                            $eb.message('error','请填写规则名称');
+                            bool = false;
+                        }else if(!item.detail.length){
+                            $eb.message('error','请设置规则属性');
+                            bool = false;
+                        }
+                    });
+                    return bool;
+                },
+                attrAdd (item) {
+                    if(!item.detailValue) return false;
+                    item.detail.push(item.detailValue);
+                    item.detailValue = '';
+                },
+                handleRemove (index) {
+                    if(this.items.length > 1)
+                        this.items.splice(index,1);
+                    else
+                        $eb.message('error','请设置至少一个规则');
+                },
+                attrRemove(item,k){
+                    if(1==item.detail.length){
+                        $eb.message('error','请设置至少一个属性');
+                        return false;
+                    }
+                    item.detail.splice(k,1);
+                },
+                removeGoods(index){
+                    this.attrs.splice(index,1);
+                },
+                checkGoods(){
+                    var bool = true;
+                    this.attrs.map(function(attr){
+                        if(!bool) return ;
+                        if(!Object.keys(attr.detail).length){
+                            $eb.message('error','请选择至少一个属性');
+                            bool = false;
+                        }else if(attr.price != parseFloat(attr.price) || attr.price < 0){
+                            $eb.message('error','请输入正确的商品价格');
+                            bool = false;
+                        }else if(attr.sales != parseInt(attr.sales) || attr.sales < 0){
+                            $eb.message('error','请输入正确的商品库存');
+                            bool = false;
+                        }
+                    });
+                    return bool;
+                },
+                addGoods(type){
+                    var that = this;
+                    if(this.attrs.length){
+                        if(!this.checkGoods())return ;
+                    }
+                    $eb.axios.post("{:Url('is_format_attr',array('id'=>$id))}",{items:this.items,attrs:this.attrs}).then(function(res){
+                        if(res.data.code == 200){
+                            that.attrs = res.data.data
+                        }else{
+                            $eb.message('error',res.data.msg);
+                        }
+                    }).catch(function(err){
+                        if(res.data.code == 200){
+                            that.attrs = res.data.data
+                        }else{
+                            $eb.message('error',res.data.msg);
+                        }
+                    })
+//                    if(type === true){
+//                        this.attrs = [{
+//                            detail:{},
+//                            price:'',
+//                            sales:'',
+//                            pic:'{$image}'
+//                        }];
+//                    }else{
+//                        this.attrs.push({
+//                            detail:{},
+//                            price:'',
+//                            sales:'',
+//                            pic:'{$image}'
+//                        });
+//                    }
+                },
+                openPic(src){
+                    $eb.openImage(src);
+                },
+                uploadSuccess(data){
+                    return function(response, file, fileList){
+                        if(response.code == 200){
+                            data.pic = response.data.url;
+                        }else{
+                            $eb.message('error',response.data.msg || '图片上传失败!');
+                        }
+                    }
+                },
+                uploadError(error, file, fileList){
+                    $eb.message('error',error);
+                },
+                uploadFormatError(file, fileList){
+                    $eb.message('error','图片格式错误');
+                },
+                submit(){
+                    var that = this;
+                    that.submiting = true;
+                    if(!this.checkAttr() || !this.checkGoods()) return ;
+                    for(let attr in that.attrs){
+                        that.attrs[attr].check = false;
+                    }
+                    $eb.axios.post("{:Url('set_attr',array('id'=>$id))}",{items:this.items,attrs:this.attrs}).then(function(res){
+                        that.submiting = false;
+                        if(res.status == 200 && res.data.code == 200){
+                            $eb.message('success',res.data.msg || '编辑成功!');
+                            $eb.closeModalFrame(window.name);
+                        }else{
+                            $eb.message('error',res.data.msg || '请求失败!');
+                        }
+                    }).catch(function(err){
+                        $eb.message('error',err);
+                    })
+                },
+                clear(){
+                    var that = this;
+                    requirejs(['sweetalert'], function (swel) {
+                        swel({
+                            title: "您确定要清空商品属性吗",
+                            text: "删除后将无法恢复,请谨慎操作!",
+                            type: "warning",
+                            showCancelButton: true,
+                            confirmButtonColor: "#DD6B55",
+                            confirmButtonText: "是的,我要清空!",
+                            cancelButtonText: "让我再考虑一下…",
+                            closeOnConfirm: false,
+                            closeOnCancel: false
+                        }).then(function () {
+                            $eb.axios.post("{:Url('clear_attr',array('id'=>$id))}", {
+                                items: that.items,
+                                attrs: that.attrs
+                            }).then(function (res) {
+                                if (res.status == 200 && res.data.code == 200) {
+                                    $eb.message('success', res.data.msg || '清空成功!');
+                                    window.location.reload();
+                                } else {
+                                    $eb.message('error', res.data.msg || '清空失败!');
+                                }
+                            }).catch(function (err) {
+                                $eb.message('error', err);
+                            })
+                        }).catch(console.log);
+                    });
+                }
+            },
+            mounted (){
+                _vm = this;
+                var resultAdmin = <?php echo $result && isset($result['attr']) && !empty($result['attr']) ? json_encode($result['attr']) : 'false'; ?>;
+                if(resultAdmin) this.hidden = true;
+            }
+        }).$mount(document.getElementById('store-attr'));
+    });
+</script>
+</body>

+ 123 - 0
app/admin/view/ump/store_integral/attr_list.php

@@ -0,0 +1,123 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
+    {include file="public/head"}
+    <script src="/static/plug/jquery-1.4.1.min.js"></script>
+    <link rel="stylesheet" href="/static/plug/layui/css/layui.css">
+    <script src="/static/plug/layui/layui.js"></script>
+    <style>
+        .layui-form-checkbox{
+            margin-top: 0!important;
+            margin-right: 0;
+        }
+        .layui-form-checkbox i{
+            border-left: 1px solid #d2d2d2;
+        }
+    </style>
+</head>
+<body>
+<form class="layui-form" action="" style="padding: 30px 50px 0px 0px;">
+    <div class="layui-form-item">
+        <label class="layui-form-label">规格选择</label>
+        <div class="layui-input-block">
+            <table class="layui-table attrTab">
+                <thead>
+                <tr>
+                    {volist name="attr.attr" id="vo"}
+                    <th>{$vo.value}</th>
+                    {/volist}
+                    <th>图片</th>
+                    <th>积分价</th>
+                    <th>消耗积分</th>
+                    <th>成本价</th>
+                    <th>原价</th>
+                    <th>库存</th>
+                    <th>限量</th>
+                    <th>商品编号</th>
+                    <th>重量</th>
+                    <th>体积</th>
+                    <th>押金</th>
+                    <th>选择</th>
+                </tr>
+                </thead>
+                <tbody>
+                {volist name="attr.value" id="vo" key="k"}
+                <tr>
+                    {volist name="$vo" id="item"}
+                    {if condition="$key eq 'pic'"}
+                    <td id="cl{$k}"><input type="hidden" name="attr[{$k}][{$key}]" class="layui-input" value="{$item}"><img src="{$item}" width="50px" onclick="createFrame('选择图片','{:Url('widget.images/index',['fodder'=>'image'])}',{w:900,h:550},'cl{$k}')"></td>
+                    {elseif condition="$key eq 'detail'"/}
+                    <input type="hidden" name="attr[{$k}][{$key}]" class="layui-input" value="{$item}">
+                    {elseif condition="$key eq 'check'"/}
+                    <td><input type="checkbox" name="ids[]" value="{$k}" {if condition="$item eq 1"}checked{/if}></td>
+                    {elseif condition="($key neq 'brokerage') AND ($key neq 'brokerage_two')"/}
+                    {if condition="($key neq 'price') AND ($key neq 'quota') AND ($key neq 'integral')"}
+                    <td style="text-align: center"><span>{$item}</span><input type="hidden" name="attr[{$k}][{$key}]" class="layui-input" value="{$item}"></td>
+                    {else/}
+                    <td><input type="number" name="attr[{$k}][{$key}]" class="layui-input max" value="{$item}" min="0" max="{if condition="$key eq 'quota'"}{$vo['stock']}{else/}{$vo['ot_price']}{/if}" oninput="checknum(this)"></td>
+                    {/if}
+                    {/if}
+                    {/volist}
+                </tr>
+                {/volist}
+                </tbody>
+            </table>
+        </div>
+    </div>
+    <div class="layui-form-item">
+        <div class="layui-input-block">
+            <input type="hidden" name="id" value="{$id}">
+            <button type="button" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
+        </div>
+    </div>
+</form>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+<script>
+    var cl = '';
+    layui.use('form', function () {
+        var form = layui.form;
+        form.on('submit(formDemo)', function (data) {
+            layList.basePost('save_attr', data.field, function (res) {
+                parent.layer.close(parent.layer.getFrameIndex(window.name));
+                parent.layer.msg(res.msg, {icon:1,time:2000});
+            }, function (res) {
+                parent.layer.msg(res.msg, {icon:1,time:2000});
+            });
+        });
+    });
+    function createFrame(title,src,opt,k){
+        cl = k;
+        opt === undefined && (opt = {});
+        var h = parent.document.body.clientHeight - 100;
+        return layer.open({
+            type: 2,
+            title:title,
+            area: [(opt.w || 700)+'px', (opt.h || h)+'px'],
+            fixed: false, //不固定
+            maxmin: true,
+            moveOut:false,//true  可以拖出窗外  false 只能在窗内拖
+            anim:5,//出场动画 isOutAnim bool 关闭动画
+            offset:'auto',//['100px','100px'],//'auto',//初始位置  ['100px','100px'] t[ 上 左]
+            shade:0,//遮罩
+            resize:true,//是否允许拉伸
+            content: src,//内容
+            move:'.layui-layer-title'
+        });
+    }
+    function changeIMG(index,pic){
+        $('#'+cl).children('input').val(pic);
+        $('#'+cl).children('img').attr('src',pic);
+    }
+    function checknum(e){
+        if(parseInt(e.value)>parseInt(e.max)){
+            $(e).val(e.max);
+        }
+        if(parseInt(e.value)<0){
+            $(e).val(0);
+        }
+    }
+</script>
+</body>
+</html>

+ 215 - 0
app/admin/view/ump/store_integral/index.php

@@ -0,0 +1,215 @@
+{extend name="public/container"}
+{block name="head_top"}
+<script type="text/javascript" src="{__PLUG_PATH}jquery.downCount.js"></script>
+{/block}
+{block name="content"}
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15"  id="app">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">积分商品搜索</div>
+                <div class="layui-card-body">
+                    <div class="alert alert-success alert-dismissable">
+                        <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
+                        目前拥有{$countSeckill}个积分商品
+                    </div>
+                    <form class="layui-form">
+                        <div class="layui-form-item">
+                            <div class="layui-inline">
+                                <label class="layui-form-label">搜  索:</label>
+                                <div class="layui-input-inline">
+                                    <input type="text" name="store_name" lay-verify="store_name" style="width: 100%" autocomplete="off" placeholder="请输入商品名称,关键字,编号" class="layui-input">
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <label class="layui-form-label">积分状态:</label>
+                                <div class="layui-input-inline">
+                                    <select name="status" lay-verify="status">
+                                        <option value="">全部</option>
+                                        <option value="1">开启</option>
+                                        <option value="0">关闭</option>
+                                    </select>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="layui-form-item">
+                            <label class="layui-form-label">
+                                <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="search" style="font-size:14px;line-height: 9px;">
+                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索</button>
+                                <button lay-submit="export" lay-filter="export" class="layui-btn layui-btn-primary layui-btn-sm">
+                                    <i class="layui-icon layui-icon-delete layuiadmin-button-btn" ></i> Excel导出</button>
+                            </label>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">积分商品列表</div>
+                <div class="layui-card-body">
+                    <div class="layui-btn-container">
+                        <a class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}',{h:700,w:1100});">添加积分商品</a>
+                    </div>
+                    <table class="layui-hide" id="seckillList" lay-filter="seckillList"></table>
+                    <script type="text/html" id="status">
+                        <input type='checkbox' name='status' lay-skin='switch' value="{{d.id}}" lay-filter='status' lay-text='开启|关闭'  {{ d.status == 1 ? 'checked' : '' }}>
+                    </script>
+                    <script type="text/html" id="barDemo">
+                        <button type="button" class="layui-btn layui-btn-xs" onclick="$eb.createModalFrame('{{d.title}}-设置规格','{:Url('attr_list')}?id={{d.id}}',{h:1000,w:1400});"><i class="layui-icon layui-icon-util"></i>规格</button>
+
+                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作<span class="caret"></span></button>
+                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
+                            <li>
+                                <a href="javascript:void(0);" onclick="$eb.createModalFrame('{{d.title}}-编辑','{:Url('edit')}?id={{d.id}}')"><i class="layui-icon layui-icon-edit"></i> 编辑活动</a>
+                            </li>
+                            <li>
+                                <a href="javascript:void(0);" onclick="$eb.createModalFrame('{{d.title}}-编辑内容','{:Url('edit_content')}?id={{d.id}}')"><i class="layui-icon layui-icon-edit"></i>编辑内容</a>
+                            </li>
+                            <li>
+                                <a href="javascript:void(0);" class="delstor" lay-event='delstor'><i class="layui-icon layui-icon-delete"></i> 删除</a>
+                            </li>
+                        </ul>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+<script src="{__FRAME_PATH}js/content.min.js?v=1.0.0"></script>
+<script>
+    layList.form.render();
+    layList.tableList('seckillList',"{:Url('get_seckill_list')}",function () {
+        return [
+            {field: 'id', title: 'ID', sort: true,width:'6%',event:'id'},
+            {field: 'image', title: '商品图片', width: '10%',templet: '<p><img src="{{d.image}}" alt="{{d.title}}" class="open_image" data-image="{{d.image}}"></p>'},
+            {field: 'title', title: '活动标题'},
+            {field: 'info', title: '活动简介',width:'20%'},
+            {field: 'ot_price', title: '原价',width:'6%'},
+            {field: 'price', title: '积分价',width:'6%'},
+            {field: 'integral', title: '消耗积分',width:'6%'},
+            {field: 'quota_show', title: '限量',width:'6%'},
+            {field: 'quota', title: '限量剩余',width:'6%'},
+            {field: 'status', title: '状态',width:'6%',toolbar:"#status"},
+            {field: 'right', title: '操作',width:'10%', align: 'center', toolbar: '#barDemo'}
+        ]
+    });
+    layList.tool(function (event,data,obj) {
+        switch (event) {
+            case 'delstor':
+                var url=layList.U({c:'ump.store_integral',a:'delete',q:{id:data.id}});
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                        }else
+                            return Promise.reject(res.data.msg || '删除失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                })
+                break;
+        }
+    })
+    $(document).click(function (e) {
+        $('.layui-nav-child').hide();
+    })
+    function dropdown(that){
+        var oEvent = arguments.callee.caller.arguments[0] || event;
+        oEvent.stopPropagation();
+        var offset = $(that).offset();
+        var top=offset.top-$(window).scrollTop();
+        var index = $(that).parents('tr').data('index');
+        $('.layui-nav-child').each(function (key) {
+            if (key != index) {
+                $(this).hide();
+            }
+        })
+        if($(document).height() < top+$(that).next('ul').height()){
+            $(that).next('ul').css({
+                'padding': 10,
+                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
+                'min-width': 'inherit',
+                'position': 'absolute'
+            }).toggle();
+        }else{
+            $(that).next('ul').css({
+                'padding': 10,
+                'top':$(that).parent('td').height() / 2 + $(that).height(),
+                'min-width': 'inherit',
+                'position': 'absolute'
+            }).toggle();
+        }
+    }
+    layList.search('search',function(where){
+        layList.reload(where);
+        // setTime();
+    });
+    layList.search('export',function(where){
+        location.href=layList.U({c:'ump.store_integral',a:'save_excel',q:{status:where.status,store_name:where.store_name}});
+    })
+    layList.switch('status',function (odj,value,name) {
+        if (odj.elem.checked == true) {
+            layList.baseGet(layList.Url({
+                c: 'ump.store_integral',
+                a: 'set_seckill_status',
+                p: {status: 1, id: value}
+            }), function (res) {
+                layList.msg(res.msg);
+            }, function () {
+                odj.elem.checked = false;
+                layui.form.render();
+                layer.open({
+                    type: 1
+                    ,offset: 'auto'
+                    ,id: 'layerDemoauto' //防止重复弹出
+                    ,content: '<div style="padding: 20px 100px;">请先配置规格</div>'
+                    ,btn: '设置规格'
+                    ,btnAlign: 'c' //按钮居中
+                    ,shade: 0 //不显示遮罩
+                    ,yes: function(){
+                        layer.closeAll();
+                        $eb.createModalFrame('设置规格','{:Url('attr_list')}?id='+value+'',{h:1000,w:1400});
+                    }
+                });
+            });
+        } else {
+            layList.baseGet(layList.Url({
+                c: 'ump.store_integral',
+                a: 'set_seckill_status',
+                p: {status: 0, id: value}
+            }), function (res) {
+                layList.msg(res.msg);
+            });
+        }
+    })
+    $('.js-group-btn').on('click',function(){
+        $('.js-group-btn').css({zIndex:1});
+        $(this).css({zIndex:2});
+    });
+    $('#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);
+            });
+        })
+    });
+    $(document).on('click',".open_image",function (e) {
+        var image = $(this).data('image');
+        $eb.openImage(image);
+    });
+</script>
+{/block}

+ 104 - 0
app/admin/view/ump/store_integral/product_list.php

@@ -0,0 +1,104 @@
+{extend name="public/container"}
+{block name="content"}
+<style type="text/css">
+    .form-add{position: fixed;left: 0;bottom: 0;width:100%;}
+    .form-add .sub-btn{border-radius: 0;width: 100%;padding: 6px 0;font-size: 14px;outline: none;border: none;color: #fff;background-color: #2d8cf0;}
+</style>
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15"  id="app">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">搜索条件</div>
+                <div class="layui-card-body">
+                    <form class="layui-form layui-form-pane" action="">
+                        <div class="layui-inline">
+                            <label class="layui-form-label">所有分类</label>
+                            <div class="layui-input-block">
+                                <select name="cate_id">
+                                    <option value=" ">全部</option>
+                                    {volist name='cate' id='vo'}
+                                    <option value="{$vo.id}">{$vo.html}{$vo.cate_name}</option>
+                                    {/volist}
+                                </select>
+                            </div>
+                        </div>
+                        <div class="layui-inline">
+                            <label class="layui-form-label">商品名称</label>
+                            <div class="layui-input-block">
+                                <input type="text" name="store_name" class="layui-input" placeholder="请输入商品名称,关键字,编号">
+                            </div>
+                        </div>
+                        <div class="layui-inline">
+                            <div class="layui-input-inline">
+                                <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
+                                    <i class="layui-icon layui-icon-search"></i>搜索</button>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-body">
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+                    <!--图片-->
+                    <script type="text/html" id="image">
+                        <img style="cursor: pointer" lay-event="open_image" src="{{d.image}}">
+                    </script>
+                    <!--操作-->
+                    <script type="text/html" id="act">
+                        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm select" lay-event='select'>选择</button>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name='script'}
+<script>
+    var parentinputname = '{$Request.param.fodder}';
+    layList.form.render();
+    //加载列表
+    layList.tableList('List',"{:Url('store.store_product/product_ist',['type'=>1])}",function (){
+        return [
+            {field: 'id', title: 'ID', sort: true,event:'id',width:'8%'},
+            {field: 'image', title: '商品图片',templet:'#image',width:'12%'},
+            {field: 'store_name', title: '商品名称',templet:'#store_name',width:'40%'},
+            {field: 'right', title: '操作',align:'center',toolbar:'#act'}
+        ]
+    });
+    //点击事件绑定
+    layList.tool(function (event,data) {
+        switch (event) {
+            case 'select':
+                parent.$f.changeField('product',data.image);
+                parent.$f.changeField('product_id',data.id);
+                parent.$f.changeField('title',data.store_name);
+                parent.$f.changeField('store_name',data.store_name);
+                parent.$f.changeField('info',data.store_info);
+                parent.$f.changeField('unit_name',data.unit_name);
+                parent.$f.changeField('temp_id',data.temp_id.toString());
+                parent.$f.changeField('image',data.image);
+                parent.$f.changeField('images',eval('('+data.slider_image+')'));
+                parent.$f.changeField('price',data.price);
+                parent.$f.changeField('ot_price',data.ot_price);
+                parent.$f.changeField('cost',data.cost);
+                parent.$f.changeField('stock',data.stock);
+                parent.$f.changeField('sales',data.sales);
+                parent.$f.changeField('sort',data.sort);
+                parent.$f.changeField('num',1);
+                parent.$f.changeField('give_integral',data.give_integral);
+                parent.$f.changeField('description',data.description);
+                parent.$f.closeModal(parentinputname);
+                break;
+        }
+    })
+    //查询
+    layList.search('search',function(where){
+        layList.reload(where);
+    });
+</script>
+{/block}

+ 1 - 0
app/admin/view/ump/store_seckill/attr_list.php

@@ -37,6 +37,7 @@
                     <th>商品编号</th>
                     <th>重量</th>
                     <th>体积</th>
+                    <th>押金</th>
                     <th>选择</th>
                 </tr>
                 </thead>

+ 1 - 1
app/admin/view/user/user/index.php

@@ -205,7 +205,7 @@
                     <div class="layui-btn-group conrelTable">
 <!--                        <button class="layui-btn layui-btn-sm layui-btn-danger" type="button" data-type="set_status_f"><i class="fa fa-ban"></i>封禁</button>-->
 <!--                        <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_status_j"><i class="fa fa-check-circle-o"></i>解封</button>-->
-                        <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_grant"><i class="fa fa-check-circle-o"></i>发送优惠券</button>
+<!--                        <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_grant"><i class="fa fa-check-circle-o"></i>发送优惠券</button>-->
                         <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_custom"><i class="fa fa-check-circle-o"></i>发送客服图文消息</button>
                         <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_group"><i class="fa fa-check-circle-o" ></i>批量设置分组</button>
 <!--                        <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-type="set_template"><i class="fa fa-check-circle-o"></i>发送模板消息</button>-->

+ 5 - 5
app/api/controller/AuthController.php

@@ -197,11 +197,11 @@ class AuthController
             return app('json')->fail($e->getError());
         }
         $verifyCode = CacheService::get('code_' . $account);
-        if (!$verifyCode)
-            return app('json')->fail('请先获取验证码');
-        $verifyCode = substr($verifyCode, 0, 6);
-        if ($verifyCode != $captcha)
-            return app('json')->fail('验证码错误');
+//        if (!$verifyCode)
+//            return app('json')->fail('请先获取验证码');
+//        $verifyCode = substr($verifyCode, 0, 6);
+//        if ($verifyCode != $captcha)
+//            return app('json')->fail('验证码错误');
         if (strlen(trim($password)) < 6 || strlen(trim($password)) > 16)
             return app('json')->fail('密码必须是在6到16位之间');
         if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码');

+ 99 - 0
app/api/controller/activity/StoreIntegralController.php

@@ -0,0 +1,99 @@
+<?php
+
+namespace app\api\controller\activity;
+
+use app\admin\model\store\StoreDescription;
+use app\admin\model\store\StoreProductAttrValue;
+use app\models\store\StoreIntegral;
+use app\models\store\StoreProductAttr;
+use app\models\store\StoreProductRelation;
+use app\models\store\StoreProductReply;
+//use app\models\store\StoreSeckill;
+use app\models\store\StoreVisit;
+use app\Request;
+use crmeb\services\GroupDataService;
+use crmeb\services\QrcodeService;
+use crmeb\services\UtilService;
+
+/**
+ * 秒杀产品类
+ * Class StoreSeckillController
+ * @package app\api\controller\activity
+ */
+class StoreIntegralController
+{
+    /**
+     * 积分产品列表
+     * @param Request $request
+     * @param $time
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function lst(Request $request)
+    {
+        list($page, $limit) = UtilService::getMore([
+            ['page', 0],
+            ['limit', 0],
+        ], $request, true);
+//        var_dump(111);
+        $seckillInfo = StoreIntegral::seckillList($page, $limit);
+        if (count($seckillInfo)) {
+            foreach ($seckillInfo as $key => &$item) {
+                if ($item['quota'] > 0) {
+                    $quota = StoreProductAttrValue::where('product_id', $item['id'])->where('type', 4)->value('SUM(quota)');
+                    $percent = (int)bcmul(bcdiv(bcsub($item['quota'], $quota), $item['quota'], 2), 100, 0);
+                    $item['percent'] = $percent;
+                    $item['stock'] = $quota;
+                } else {
+                    $item['percent'] = 100;
+                    $item['stock'] = 0;
+                }
+
+            }
+        }
+        return app('json')->successful($seckillInfo);
+    }
+
+    /**
+     * 秒杀产品详情
+     * @param Request $request
+     * @param $id
+     * @return mixed
+     */
+    public function detail(Request $request, $id, $time = 0)
+    {
+        if (!$id || !($storeInfo = StoreIntegral::getValidProduct($id))) return app('json')->fail('商品不存在或已下架!');
+        $storeInfo = $storeInfo->hidden(['cost', 'add_time', 'is_del'])->toArray();
+        $siteUrl = sys_config('site_url');
+        $storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
+        $storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
+        $storeInfo['code_base'] = QrcodeService::getWechatQrcodePath($id . '_seckill_detail_wap.jpg', '/activity/seckill_detail/' . $id . '/' . $time);
+        $uid = $request->uid();
+        $storeInfo['userLike'] = StoreProductRelation::isProductRelation($id, $uid, 'like', 'product_seckill');
+        $storeInfo['like_num'] = StoreProductRelation::productRelationNum($id, 'like', 'product_seckill');
+        $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($storeInfo['product_id'], $uid, 'collect');
+        $storeInfo['uid'] = $uid;
+        $storeInfo['description'] = htmlspecialchars_decode(StoreDescription::getDescription($id, 4));
+        $data['storeInfo'] = $storeInfo;
+        StoreVisit::setView($uid, $id, $storeInfo['product_id'], 'viwe');
+        $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['product_id']);
+        $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['product_id'])->count();
+        if ($data['replyCount']) {
+            $goodReply = StoreProductReply::productValidWhere()->where('product_id', $storeInfo['product_id'])->where('product_score', 5)->count();
+            $data['replyChance'] = $goodReply;
+            if ($goodReply) {
+                $data['replyChance'] = bcdiv($goodReply, $data['replyCount'], 2);
+                $data['replyChance'] = bcmul($data['replyChance'], 100, 3);
+            }
+        } else $data['replyChance'] = 0;
+        list($productAttr, $productValue) = StoreProductAttr::getProductAttrDetail($id, $uid, 0, 4);
+        foreach ($productValue as $k => $v) {
+            $productValue[$k]['product_stock'] = StoreProductAttrValue::where('product_id',$storeInfo['product_id'])->where('suk',$v['suk'])->where('type',0)->value('stock');
+        }
+        $data['productAttr'] = $productAttr;
+        $data['productValue'] = $productValue;
+        return app('json')->successful($data);
+    }
+}

+ 75 - 0
app/api/controller/admin/StoreOrderController.php

@@ -433,6 +433,81 @@ class StoreOrderController
         }
     }
 
+
+    /**
+     * 订单退押金
+     * @param Request $request
+     * @return mixed
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function back_deposit(Request $request)
+    {
+        list($orderId, $price, $type) = UtilService::postMore([
+            ['order_id', ''],
+            ['price', 0],
+            ['type', 1],
+        ], $request, true);
+        if (!strlen(trim($orderId))) return app('json')->fail('参数错误');
+        $orderInfo = StoreOrder::getAdminOrderDetail($orderId);
+        if (!$orderInfo) return app('json')->fail('数据不存在!');
+        $orderInfo = $orderInfo->toArray();
+        if ($type == 1)
+            $data['deposit_status'] = 1;
+        else if ($type == 2) {
+            $data['deposit_status'] = 0;
+        } else
+            return app('json')->fail('退款修改状态错误');
+        if ($orderInfo['deposit'] == 0 || $type == 2) {
+            StoreOrder::update($data, ['order_id' => $orderId]);
+            return app('json')->successful('修改退款状态成功!');
+        }
+        if ($orderInfo['deposit'] == $orderInfo['deposit_back']) return app('json')->fail('已退完押金!不能再退了');
+        if (!$price) return app('json')->fail('请输入退押金额');
+        $data['deposit_back'] = bcadd($price, $orderInfo['deposit_back'], 2);
+        $bj = bccomp((float)$orderInfo['deposit'], (float)$data['deposit_back'], 2);
+        if ($bj < 0) return app('json')->fail('退款押金大于支付押金,请修改退款押金');
+        $refundData['pay_price'] = bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2);
+        $refundData['refund_price'] = $price;
+        if ($orderInfo['pay_type'] == 'weixin') {
+            if ($orderInfo['is_channel'] == 1) {// 小程序
+                try {
+                    MiniProgramService::payOrderRefund($orderInfo['order_id'], $refundData);
+                } catch (\Exception $e) {
+                    return app('json')->fail($e->getMessage());
+                }
+            } else {// 公众号
+                try {
+                    WechatService::payOrderRefund($orderInfo['order_id'], $refundData);
+                } catch (\Exception $e) {
+                    return app('json')->fail($e->getMessage());
+                }
+            }
+        } else if ($orderInfo['pay_type'] == 'yue') {//余额
+            StoreOrder::beginTrans();
+            $userInfo = User::getUserInfo($orderInfo['uid'], 'now_money');
+            if (!$userInfo) {
+                StoreOrder::rollbackTrans();
+                return app('json')->fail('订单用户不存在');
+            }
+            $res1 = User::bcInc($orderInfo['uid'], 'now_money', $price, 'uid');
+            $res2 = UserBill::income('商品退押金', $orderInfo['uid'], 'now_money', 'pay_deposit_refund', $price, $orderInfo['id'], bcadd($userInfo['now_money'], $price, 2), '订单退押金到余额' . floatval($price) . '元');
+            $res = $res1 && $res2;
+            StoreOrder::checkTrans($res);
+            if (!$res) return app('json')->fail('余额退押金失败!');
+        }
+        $resEdit = StoreOrder::edit($data, $orderInfo['id'], 'id');
+        if ($resEdit) {
+            StoreOrderStatus::status($orderInfo['id'], 'refund_deposit', '退押金给用户' . $price . '元');
+            return app('json')->successful('修改成功!');
+        } else {
+            StoreOrderStatus::status($orderInfo['id'], 'refund_deposit', '退押金给用户' . $price . '元失败');
+            return app('json')->successful('修改失败!');
+        }
+    }
+
     /**
      * 门店核销
      * @param Request $request

+ 11 - 8
app/api/controller/order/StoreOrderController.php

@@ -69,17 +69,20 @@ class StoreOrderController
         $seckill_id = 0;
         $combination_id = 0;
         $bargain_id = 0;
+        $integral_id = 0;
         if (count($cartIdA) == 1) {
             $seckill_id = StoreCart::where('id', $cartId)->value('seckill_id');
             $combination_id = StoreCart::where('id', $cartId)->value('combination_id');
             $bargain_id = StoreCart::where('id', $cartId)->value('bargain_id');
+            $integral_id = StoreCart::where('id', $cartId)->value('integral_id');
         }
-        $data['deduction'] = $seckill_id || $combination_id || $bargain_id;
+        $data['deduction'] = $seckill_id || $combination_id || $bargain_id || $integral_id;
         $data['usableCoupon'] = $usableCoupon;
         $data['addressInfo'] = UserAddress::getUserDefaultAddress($uid);
         $data['seckill_id'] = $seckill_id;
         $data['combination_id'] = $combination_id;
         $data['bargain_id'] = $bargain_id;
+        $data['integral_id'] = $integral_id;
         $data['cartInfo'] = $cartInfo;
         $data['priceGroup'] = $priceGroup;
         $data['orderKey'] = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
@@ -118,8 +121,8 @@ class StoreOrderController
         $uid = $request->uid();
         if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
             return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
-        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
-            'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''],
+        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $integral_id, $formId, $bargainId, $shipping_type) = UtilService::postMore([
+            'addressId', 'couponId', ['payType', 'yue'], ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['integral_id', 0], ['formId', ''], ['bargainId', ''],
             ['shipping_type', 1],
         ], $request, true);
         $payType = strtolower($payType);
@@ -138,7 +141,7 @@ class StoreOrderController
             if (StoreOrder::getIsOrderPink($pinkId, $request->uid()))
                 return app('json')->status('ORDER_EXIST', '订单生成失败,你已经参加该团了,请先支付订单', ['orderId' => StoreOrder::getStoreIdPink($pinkId, $request->uid())]);
         }
-        $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, true, 0, $shipping_type);
+        $priceGroup = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $integral_id, true, 0, $shipping_type);
         if ($priceGroup)
             return app('json')->status('NONE', 'ok', $priceGroup);
         else
@@ -161,8 +164,8 @@ class StoreOrderController
         $uid = $request->uid();
         if (StoreOrder::be(['order_id|unique' => $key, 'uid' => $uid, 'is_del' => 0]))
             return app('json')->status('extend_order', '订单已生成', ['orderId' => $key, 'key' => $key]);
-        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
-            'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
+        list($addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $integral_id, $formId, $bargainId, $from, $shipping_type, $real_name, $phone, $storeId) = UtilService::postMore([
+            'addressId', 'couponId', 'payType', ['useIntegral', 0], 'mark', ['combinationId', 0], ['pinkId', 0], ['seckill_id', 0], ['integral_id', 0], ['formId', ''], ['bargainId', ''], ['from', 'weixin'],
             ['shipping_type', 1], ['real_name', ''], ['phone', ''], ['store_id', 0]
         ], $request, true);
         $payType = strtolower($payType);
@@ -186,7 +189,7 @@ class StoreOrderController
             $isChannel = 0;
         elseif ($from == 'weixinh5')
             $isChannel = 2;
-        $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, false, $isChannel, $shipping_type, $real_name, $phone, $storeId);
+        $order = StoreOrder::cacheKeyCreateOrder($request->uid(), $key, $addressId, $payType, (int)$useIntegral, $couponId, $mark, $combinationId, $pinkId, $seckill_id, $bargainId, $integral_id, false, $isChannel, $shipping_type, $real_name, $phone, $storeId);
         if ($order === false) return app('json')->fail(StoreOrder::getErrorInfo('订单生成失败'));
         $orderId = $order['order_id'];
         $info = compact('orderId', 'key');
@@ -200,7 +203,7 @@ class StoreOrderController
                     $orderInfo = $orderInfo->toArray();
                     if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
                     //支付金额为0
-                    if (bcsub((float)$orderInfo['pay_price'], 0, 2) <= 0) {
+                    if (bcsub((float)bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2), 0, 2) <= 0) {
                         //创建订单jspay支付
                         $payPriceStatus = StoreOrder::jsPayPrice($orderId, $uid, $formId);
                         if ($payPriceStatus)//0元支付成功

+ 19 - 17
app/api/controller/store/StoreCartController.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace app\api\controller\store;
 
 use app\models\store\StoreBargainUserHelp;
@@ -34,18 +35,19 @@ class StoreCartController
      */
     public function add(Request $request)
     {
-        list($productId, $cartNum, $uniqueId, $combinationId, $secKillId, $bargainId, $new) = UtilService::postMore([
-            ['productId',0],//普通产品编号
-            ['cartNum',1], //购物车数量
-            ['uniqueId',''],//属性唯一值
-            ['combinationId',0],//拼团产品编号
-            ['secKillId',0],//秒杀产品编号
-            ['bargainId',0],//砍价产品编号
-            ['new',1], // 1 加入购物车直接购买  0 加入购物车
+        list($productId, $cartNum, $uniqueId, $combinationId, $secKillId, $bargainId, $integralId, $new) = UtilService::postMore([
+            ['productId', 0],//普通产品编号
+            ['cartNum', 1], //购物车数量
+            ['uniqueId', ''],//属性唯一值
+            ['combinationId', 0],//拼团产品编号
+            ['secKillId', 0],//秒杀产品编号
+            ['bargainId', 0],//砍价产品编号
+            ['integralId', 0],//积分产品编号
+            ['new', 1], // 1 加入购物车直接购买  0 加入购物车
         ], $request, true);
         if (!$productId || !is_numeric($productId)) return app('json')->fail('参数错误');
         if ($bargainId && StoreBargainUserHelp::getSurplusPrice($bargainId, $request->uid())) return app('json')->fail('请先砍价');
-        $res = StoreCart::setCart($request->uid(), $productId, $cartNum, $uniqueId, 'product', $new, $combinationId, $secKillId, $bargainId);
+        $res = StoreCart::setCart($request->uid(), $productId, $cartNum, $uniqueId, 'product', $new, $combinationId, $secKillId, $bargainId, $integralId);
         if (!$res) return app('json')->fail(StoreCart::getErrorInfo());
         else  return app('json')->successful('ok', ['cartId' => $res->id]);
     }
@@ -58,11 +60,11 @@ class StoreCartController
     public function del(Request $request)
     {
         list($ids) = UtilService::postMore([
-            ['ids',[]],//购物车编号
+            ['ids', []],//购物车编号
         ], $request, true);
         if (!count($ids))
             return app('json')->fail('参数错误!');
-        if(StoreCart::removeUserCart($request->uid(), $ids))
+        if (StoreCart::removeUserCart($request->uid(), $ids))
             return app('json')->successful();
         return app('json')->fail('清除失败!');
     }
@@ -79,12 +81,12 @@ class StoreCartController
     public function num(Request $request)
     {
         list($id, $number) = UtilService::postMore([
-            ['id',0],//购物车编号
-            ['number',0],//购物车编号
+            ['id', 0],//购物车编号
+            ['number', 0],//购物车编号
         ], $request, true);
         if (!$id || !$number || !is_numeric($id) || !is_numeric($number)) return app('json')->fail('参数错误!');
         $res = StoreCart::changeUserCartNum($id, $number, $request->uid());
-        if ($res)  return app('json')->successful();
+        if ($res) return app('json')->successful();
         else return app('json')->fail(StoreCart::getErrorInfo('修改失败'));
     }
 
@@ -96,10 +98,10 @@ class StoreCartController
     public function count(Request $request)
     {
         list($numType) = UtilService::postMore([
-            ['numType',true],//购物车编号
+            ['numType', true],//购物车编号
         ], $request, true);
-        if(!(int)$numType) $numType = false;
-        return  app('json')->success('ok', ['count'=>StoreCart::getUserCartNum($request->uid(), 'product', $numType)]);
+        if (!(int)$numType) $numType = false;
+        return app('json')->success('ok', ['count' => StoreCart::getUserCartNum($request->uid(), 'product', $numType)]);
     }
 
 }

+ 1 - 1
app/http/middleware/AllowOriginMiddleware.php

@@ -22,7 +22,7 @@ class AllowOriginMiddleware implements MiddlewareInterface
      */
     protected $header = [
         'Access-Control-Allow-Origin' => '*',
-        'Access-Control-Allow-Headers' => 'Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
+        'Access-Control-Allow-Headers' => 'LatLon,Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
         'Access-Control-Allow-Methods' => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
         'Access-Control-Max-Age' => '1728000'
     ];

+ 7 - 1
app/http/middleware/AuthTokenMiddleware.php

@@ -25,8 +25,11 @@ class AuthTokenMiddleware implements MiddlewareInterface
     {
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         $authInfo = null;
+//        var_dump($request->action());
+//        var_dump($request->controller());
         $token = trim(ltrim($request->header('Authori-zation'), 'Bearer'));
-        if(!$token)  $token = trim(ltrim($request->header('Authorization'), 'Bearer'));//正式版,删除此行,某些服务器无法获取到token调整为 Authori-zation
+        $location = $request->header('LatLon', '0,0');
+        if (!$token) $token = trim(ltrim($request->header('Authorization'), 'Bearer'));//正式版,删除此行,某些服务器无法获取到token调整为 Authori-zation
         try {
             $authInfo = UserRepository::parseToken($token);
         } catch (AuthException $e) {
@@ -42,6 +45,9 @@ class AuthTokenMiddleware implements MiddlewareInterface
                 return $authInfo['tokenData'];
             });
         }
+        Request::macro('location', function () use ($location) {
+            return $location;
+        });
         Request::macro('isLogin', function () use (&$authInfo) {
             return !is_null($authInfo);
         });

+ 151 - 127
app/models/store/StoreCart.php

@@ -41,78 +41,91 @@ class StoreCart extends BaseModel
         return time();
     }
 
-    public static function setCart($uid,$product_id,$cart_num = 1,$product_attr_unique = '',$type='product',$is_new = 0,$combination_id=0,$seckill_id = 0,$bargain_id = 0)
+    public static function setCart($uid, $product_id, $cart_num = 1, $product_attr_unique = '', $type = 'product', $is_new = 0, $combination_id = 0, $seckill_id = 0, $bargain_id = 0, $integral_id = 0)
     {
-        if($cart_num < 1) $cart_num = 1;
-        if($seckill_id){
+        if ($cart_num < 1) $cart_num = 1;
+        if ($seckill_id) {
             $StoreSeckillinfo = StoreSeckill::getValidProduct($seckill_id);
-            if(!$StoreSeckillinfo)
+            if (!$StoreSeckillinfo)
                 return self::setErrorInfo('该产品已下架或删除');
             $userbuycount = StoreOrder::where('uid', $uid)->where('paid', 1)->where('seckill_id', $seckill_id)->count();
-            if($StoreSeckillinfo['num'] <= $userbuycount || $StoreSeckillinfo['num'] < $cart_num)
-                return self::setErrorInfo('每人限购'.$StoreSeckillinfo['num'].'件');
-            $res = StoreProductAttrValue::where('product_id',$seckill_id)->where('unique',$product_attr_unique)->where('type',1)->field('suk,quota')->find();
-            if($cart_num > $res['quota'])
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
-            $product_stock = StoreProductAttrValue::where('product_id',$StoreSeckillinfo['product_id'])->where('suk',$res['suk'])->where('type',0)->value('stock');
-            if($product_stock < $cart_num)
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
-        }elseif($bargain_id){
-            if(!StoreBargain::validBargain($bargain_id))
+            if ($StoreSeckillinfo['num'] <= $userbuycount || $StoreSeckillinfo['num'] < $cart_num)
+                return self::setErrorInfo('每人限购' . $StoreSeckillinfo['num'] . '件');
+            $res = StoreProductAttrValue::where('product_id', $seckill_id)->where('unique', $product_attr_unique)->where('type', 1)->field('suk,quota')->find();
+            if ($cart_num > $res['quota'])
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+            $product_stock = StoreProductAttrValue::where('product_id', $StoreSeckillinfo['product_id'])->where('suk', $res['suk'])->where('type', 0)->value('stock');
+            if ($product_stock < $cart_num)
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+        } elseif ($bargain_id) {
+            if (!StoreBargain::validBargain($bargain_id))
                 return self::setErrorInfo('该产品已下架或删除');
             $StoreBargainInfo = StoreBargain::getBargain($bargain_id);
-            $res = StoreProductAttrValue::where('product_id',$bargain_id)->where('type',2)->field('suk,quota')->find();
-            if($cart_num > $res['quota'])
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
-            $product_stock = StoreProductAttrValue::where('product_id',$StoreBargainInfo['product_id'])->where('suk',$res['suk'])->where('type',0)->value('stock');
-            if($product_stock < $cart_num)
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
-        }elseif($combination_id){//拼团
+            $res = StoreProductAttrValue::where('product_id', $bargain_id)->where('type', 2)->field('suk,quota')->find();
+            if ($cart_num > $res['quota'])
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+            $product_stock = StoreProductAttrValue::where('product_id', $StoreBargainInfo['product_id'])->where('suk', $res['suk'])->where('type', 0)->value('stock');
+            if ($product_stock < $cart_num)
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+        } elseif ($combination_id) {//拼团
             $StoreCombinationInfo = StoreCombination::getCombinationOne($combination_id);
-            if(!$StoreCombinationInfo)
+            if (!$StoreCombinationInfo)
                 return self::setErrorInfo('该产品已下架或删除');
             $userbuycount = StoreOrder::where('uid', $uid)->where('paid', 1)->where('combination_id', $combination_id)->count();
-            if($StoreCombinationInfo['num'] <= $userbuycount || $StoreCombinationInfo['num'] < $cart_num)
-                return self::setErrorInfo('每人限购'.$StoreCombinationInfo['num'].'件');
-            $res = StoreProductAttrValue::where('product_id',$combination_id)->where('unique',$product_attr_unique)->where('type',3)->field('suk,quota')->find();
-            if($cart_num > $res['quota'])
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
-            $product_stock = StoreProductAttrValue::where('product_id',$StoreCombinationInfo['product_id'])->where('suk',$res['suk'])->where('type',0)->value('stock');
-            if($product_stock < $cart_num)
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
-        }else{
-            if(!StoreProduct::isValidProduct($product_id))
+            if ($StoreCombinationInfo['num'] <= $userbuycount || $StoreCombinationInfo['num'] < $cart_num)
+                return self::setErrorInfo('每人限购' . $StoreCombinationInfo['num'] . '件');
+            $res = StoreProductAttrValue::where('product_id', $combination_id)->where('unique', $product_attr_unique)->where('type', 3)->field('suk,quota')->find();
+            if ($cart_num > $res['quota'])
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+            $product_stock = StoreProductAttrValue::where('product_id', $StoreCombinationInfo['product_id'])->where('suk', $res['suk'])->where('type', 0)->value('stock');
+            if ($product_stock < $cart_num)
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+        } elseif ($integral_id) {
+            $StoreIntegralInfo = StoreIntegral::getValidProduct($integral_id);
+            if (!$StoreIntegralInfo)
                 return self::setErrorInfo('该产品已下架或删除');
-            if(!StoreProductAttr::issetProductUnique($product_id,$product_attr_unique))
+            $userbuycount = StoreOrder::where('uid', $uid)->where('paid', 1)->where('integral_id', $integral_id)->count();
+            if ($StoreIntegralInfo['num'] <= $userbuycount || $StoreIntegralInfo['num'] < $cart_num)
+                return self::setErrorInfo('每人限购' . $StoreIntegralInfo['num'] . '件');
+            $res = StoreProductAttrValue::where('product_id', $integral_id)->where('unique', $product_attr_unique)->where('type', 4)->field('suk,quota')->find();
+            if ($cart_num > $res['quota'])
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+            $product_stock = StoreProductAttrValue::where('product_id', $StoreIntegralInfo['product_id'])->where('suk', $res['suk'])->where('type', 0)->value('stock');
+            if ($product_stock < $cart_num)
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
+        } else {
+            if (!StoreProduct::isValidProduct($product_id))
+                return self::setErrorInfo('该产品已下架或删除');
+            if (!StoreProductAttr::issetProductUnique($product_id, $product_attr_unique))
                 return self::setErrorInfo('请选择有效的产品属性');
-            if(StoreProduct::getProductStock($product_id,$product_attr_unique) < $cart_num)
-                return self::setErrorInfo('该产品库存不足'.$cart_num);
+            if (StoreProduct::getProductStock($product_id, $product_attr_unique) < $cart_num)
+                return self::setErrorInfo('该产品库存不足' . $cart_num);
         }
-        if($cart = self::where('type', $type)->where('uid', $uid)->where('product_id', $product_id)->where('product_attr_unique', $product_attr_unique)->where('is_new', $is_new)->where('is_pay', 0)->where('is_del', 0)->where('combination_id', $combination_id)->where('bargain_id', $bargain_id)->where('seckill_id', $seckill_id)->find()){
-            if($is_new)
+        if ($cart = self::where('type', $type)->where('uid', $uid)->where('product_id', $product_id)->where('product_attr_unique', $product_attr_unique)->where('is_new', $is_new)->where('is_pay', 0)->where('is_del', 0)->where('combination_id', $combination_id)->where('bargain_id', $bargain_id)->where('seckill_id', $seckill_id)->where('integral_id', $integral_id)->find()) {
+            if ($is_new)
                 $cart->cart_num = $cart_num;
             else
                 $cart->cart_num = bcadd($cart_num, $cart->cart_num, 0);
             $cart->add_time = time();
             $cart->save();
             return $cart;
-        }else{
+        } else {
             $add_time = time();
-            return self::create(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','combination_id','add_time','bargain_id','seckill_id'));
+            return self::create(compact('uid', 'product_id', 'cart_num', 'product_attr_unique', 'is_new', 'type', 'combination_id', 'add_time', 'bargain_id', 'seckill_id', 'integral_id'));
         }
     }
 
-    public static function removeUserCart($uid,$ids)
+    public static function removeUserCart($uid, $ids)
     {
-        return self::where('uid',$uid)->where('id','IN',implode(',',$ids))->update(['is_del'=>1]);
+        return self::where('uid', $uid)->where('id', 'IN', implode(',', $ids))->update(['is_del' => 1]);
     }
 
     public static function getUserCartNum($uid, $type, $numType)
     {
-        if($numType){
-            return self::where('uid',$uid)->where('type',$type)->where('is_pay',0)->where('is_del',0)->where('is_new',0)->count();
-        }else{
-            return self::where('uid',$uid)->where('type',$type)->where('is_pay',0)->where('is_del',0)->where('is_new',0)->sum('cart_num');
+        if ($numType) {
+            return self::where('uid', $uid)->where('type', $type)->where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->count();
+        } else {
+            return self::where('uid', $uid)->where('type', $type)->where('is_pay', 0)->where('is_del', 0)->where('is_new', 0)->sum('cart_num');
         }
     }
 
@@ -127,59 +140,63 @@ class StoreCart extends BaseModel
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public static function changeUserCartNum($cartId,$cartNum,$uid)
+    public static function changeUserCartNum($cartId, $cartNum, $uid)
     {
-        $count = self::where('uid',$uid)->where('id',$cartId)->count();
-        if(!$count) return self::setErrorInfo('参数错误');
-        $cartInfo = self::where('uid',$uid)->where('id',$cartId)->field('product_id,combination_id,seckill_id,bargain_id,product_attr_unique,cart_num')->find()->toArray();
+        $count = self::where('uid', $uid)->where('id', $cartId)->count();
+        if (!$count) return self::setErrorInfo('参数错误');
+        $cartInfo = self::where('uid', $uid)->where('id', $cartId)->field('product_id,combination_id,seckill_id,bargain_id,product_attr_unique,cart_num')->find()->toArray();
         $stock = 0;
-        if($cartInfo['bargain_id']){
+        if ($cartInfo['bargain_id']) {
             //TODO 获取砍价产品的库存
             $stock = 0;
-        }else if($cartInfo['seckill_id']){
+        } else if ($cartInfo['seckill_id']) {
             //TODO 获取秒杀产品的库存
             $stock = 0;
-        }else if($cartInfo['combination_id']){
+        } else if ($cartInfo['combination_id']) {
             //TODO 获取拼团产品的库存
             $stock = 0;
-        }else if($cartInfo['product_id']){
+        } else if ($cartInfo['product_id']) {
             //TODO 获取普通产品的库存
-            $stock = StoreProduct::getProductStock($cartInfo['product_id'],$cartInfo['product_attr_unique']);
+            $stock = StoreProduct::getProductStock($cartInfo['product_id'], $cartInfo['product_attr_unique']);
         }
-        if(!$stock) return self::setErrorInfo('暂无库存');
-        if(!$cartNum) return self::setErrorInfo('库存错误');
-        if($stock < $cartNum) return self::setErrorInfo('库存不足'.$cartNum);
-        if($cartInfo['cart_num'] == $cartNum) return true;
-        return self::where('uid',$uid)->where('id',$cartId)->update(['cart_num'=>$cartNum]);
+        if (!$stock) return self::setErrorInfo('暂无库存');
+        if (!$cartNum) return self::setErrorInfo('库存错误');
+        if ($stock < $cartNum) return self::setErrorInfo('库存不足' . $cartNum);
+        if ($cartInfo['cart_num'] == $cartNum) return true;
+        return self::where('uid', $uid)->where('id', $cartId)->update(['cart_num' => $cartNum]);
     }
 
-    public static function getUserProductCartList($uid,$cartIds='',$status=0)
+    public static function getUserProductCartList($uid, $cartIds = '', $status = 0)
     {
         $productInfoField = 'id,image,price,ot_price,vip_price,postage,give_integral,sales,stock,store_name,unit_name,is_show,is_del,is_postage,cost,is_sub,temp_id,store_type';
         $seckillInfoField = 'id,image,price,ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,is_show,is_del,is_postage,cost,temp_id,weight,volume,start_time,stop_time,time_id';
         $bargainInfoField = 'id,image,min_price as price,price as ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,status as is_show,is_del,is_postage,cost,temp_id,weight,volume';
         $combinationInfoField = 'id,image,price,postage,sales,stock,title as store_name,is_show,is_del,is_postage,cost,temp_id,weight,volume';
+        $IntegralInfoField = 'id,image,price,integral,ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,is_show,is_del,is_postage,cost,temp_id,weight,volume';
         $model = new self();
         $valid = $invalid = [];
-        $model = $model->where('uid',$uid)->where('type','product')->where('is_pay',0)
-            ->where('is_del',0);
-        if(!$status) $model = $model->where('is_new',0);
-        if($cartIds) $model = $model->where('id','IN',$cartIds);
+        $model = $model->where('uid', $uid)->where('type', 'product')->where('is_pay', 0)
+            ->where('is_del', 0);
+        if (!$status) $model = $model->where('is_new', 0);
+        if ($cartIds) $model = $model->where('id', 'IN', $cartIds);
         $model = $model->order('add_time DESC');
         $list = $model->select()->toArray();
-        if(!count($list)) return compact('valid','invalid');
+        if (!count($list)) return compact('valid', 'invalid');
         $now = time();
-        foreach ($list as $k=>$cart){
-            if($cart['seckill_id']){
+        foreach ($list as $k => $cart) {
+            if ($cart['seckill_id']) {
                 $product = StoreSeckill::field($seckillInfoField)
                     ->find($cart['seckill_id'])->toArray();
-            }elseif($cart['bargain_id']){
+            } elseif ($cart['bargain_id']) {
                 $product = StoreBargain::field($bargainInfoField)
                     ->find($cart['bargain_id'])->toArray();
-            }elseif($cart['combination_id']){
+            } elseif ($cart['combination_id']) {
                 $product = StoreCombination::field($combinationInfoField)
                     ->find($cart['combination_id'])->toArray();
-            }else{
+            } elseif ($cart['integral_id']) {
+                $product = StoreIntegral::field($IntegralInfoField)
+                    ->find($cart['integral_id'])->toArray();
+            } else {
                 $product = StoreProduct::field($productInfoField)
                     ->find($cart['product_id'])->toArray();
             }
@@ -187,20 +204,20 @@ class StoreCart extends BaseModel
             $cart['productInfo'] = $product;
 
             //商品不存在
-            if(!$product){
-                $model->where('id',$cart['id'])->update(['is_del'=>1]);
-            //商品删除或无库存
-            }else if(!$product['is_show'] || $product['is_del'] || !$product['stock']) {
+            if (!$product) {
+                $model->where('id', $cart['id'])->update(['is_del' => 1]);
+                //商品删除或无库存
+            } else if (!$product['is_show'] || $product['is_del'] || !$product['stock']) {
                 $invalid[] = $cart;
 
-            //秒杀产品未开启或者已结束
-            } else if ($cart['seckill_id'] && ($product['start_time'] > $now || $product['stop_time'] < $now-86400)) {
+                //秒杀产品未开启或者已结束
+            } else if ($cart['seckill_id'] && ($product['start_time'] > $now || $product['stop_time'] < $now - 86400)) {
                 $invalid[] = $product;
                 //商品属性不对应
-            } else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique']) && !$cart['combination_id'] && !$cart['seckill_id']&& !$cart['bargain_id']){
+            } else if (!StoreProductAttr::issetProductUnique($cart['product_id'], $cart['product_attr_unique']) && !$cart['combination_id'] && !$cart['seckill_id'] && !$cart['bargain_id'] && !$cart['integral_id']) {
                 $invalid[] = $cart;
-            //正常商品
-            }else{
+                //正常商品
+            } else {
 
                 if ($cart['seckill_id']) {
                     $config = SystemGroupData::get($product['time_id']);
@@ -223,64 +240,70 @@ class StoreCart extends BaseModel
 
                 }
 
-                if($cart['product_attr_unique']){
+                if ($cart['product_attr_unique']) {
                     $attrInfo = StoreProductAttr::uniqueByAttrInfo($cart['product_attr_unique']);
                     //商品没有对应的属性
-                    if(!$attrInfo || !$attrInfo['stock'])
+                    if (!$attrInfo || !$attrInfo['stock'])
                         $invalid[] = $cart;
-                    else{
+                    else {
                         $cart['productInfo']['attrInfo'] = $attrInfo;
-                        if($cart['combination_id'] || $cart['seckill_id'] || $cart['bargain_id']) {
+                        if ($cart['combination_id'] || $cart['seckill_id'] || $cart['bargain_id'] || $cart['integral_id']) {
                             $cart['truePrice'] = $attrInfo['price'];
                             $cart['vip_truePrice'] = 0;
-                        }else {
-                            $cart['truePrice'] = (float)StoreProduct::setLevelPrice($attrInfo['price'],$uid,true);
+                            $cart['integral'] = $attrInfo['integral'];
+                        } else {
+                            $cart['truePrice'] = (float)StoreProduct::setLevelPrice($attrInfo['price'], $uid, true);
                             $cart['vip_truePrice'] = (float)StoreProduct::setLevelPrice($attrInfo['price'], $uid);
+                            $cart['integral'] = $attrInfo['integral'];
                         }
+                        $cart['deposit'] = $attrInfo['deposit'];
                         $cart['trueStock'] = $attrInfo['stock'];
                         $cart['costPrice'] = $attrInfo['cost'];
                         $cart['productInfo']['image'] = empty($attrInfo['image']) ? $cart['productInfo']['image'] : $attrInfo['image'];
                         $valid[] = $cart;
                     }
-                }else{
-                    if($cart['combination_id'] || $cart['seckill_id'] || $cart['bargain_id']) {
+                } else {
+                    if ($cart['combination_id'] || $cart['seckill_id'] || $cart['bargain_id'] || $cart['integral_id']) {
                         $cart['truePrice'] = $cart['productInfo']['price'];
+                        $cart['integral'] = $cart['productInfo']['integral'] ?? 0;
                         $cart['vip_truePrice'] = 0;
-                        if($cart['bargain_id']){
-                            $cart['productInfo']['attrInfo'] = StoreProductAttrValue::where('product_id',$cart['bargain_id'])->where('type',2)->find();
+                        if ($cart['bargain_id']) {
+                            $cart['productInfo']['attrInfo'] = StoreProductAttrValue::where('product_id', $cart['bargain_id'])->where('type', 2)->find();
                         }
                         $cart['productInfo']['attrInfo']['weight'] = $product['weight'];
                         $cart['productInfo']['attrInfo']['volume'] = $product['volume'];
-                    }else {
-                        $cart['truePrice'] = (float)StoreProduct::setLevelPrice($cart['productInfo']['price'],$uid,true);
+                    } else {
+                        $cart['truePrice'] = (float)StoreProduct::setLevelPrice($cart['productInfo']['price'], $uid, true);
                         $cart['vip_truePrice'] = (float)StoreProduct::setLevelPrice($cart['productInfo']['price'], $uid);
+                        $cart['integral'] = $cart['productInfo']['integral'] ?? 0;
                     }
+                    $cart['deposit'] = $cart['productInfo']['deposit'] ?? 0;
                     $cart['trueStock'] = $cart['productInfo']['stock'];
                     $cart['costPrice'] = $cart['productInfo']['cost'];
                     $valid[] = $cart;
                 }
             }
         }
-        foreach ($valid as $k=>$cart){
-            if($cart['trueStock'] < $cart['cart_num']){
+        foreach ($valid as $k => $cart) {
+            if ($cart['trueStock'] < $cart['cart_num']) {
                 $cart['cart_num'] = $cart['trueStock'];
-                $model->where('id',$cart['id'])->update(['cart_num'=>$cart['cart_num']]);
+                $model->where('id', $cart['id'])->update(['cart_num' => $cart['cart_num']]);
                 $valid[$k] = $cart;
             }
 
-            unset($valid[$k]['uid'],$valid[$k]['is_del'],$valid[$k]['is_new'],$valid[$k]['is_pay'],$valid[$k]['add_time']);
-            if(isset($valid[$k]['productInfo'])){
-                unset($valid[$k]['productInfo']['is_del'],$valid[$k]['productInfo']['is_del'],$valid[$k]['productInfo']['is_show']);
+            unset($valid[$k]['uid'], $valid[$k]['is_del'], $valid[$k]['is_new'], $valid[$k]['is_pay'], $valid[$k]['add_time']);
+            if (isset($valid[$k]['productInfo'])) {
+                unset($valid[$k]['productInfo']['is_del'], $valid[$k]['productInfo']['is_del'], $valid[$k]['productInfo']['is_show']);
             }
         }
-        foreach ($invalid as $k=>$cart){
-            unset($valid[$k]['uid'],$valid[$k]['is_del'],$valid[$k]['is_new'],$valid[$k]['is_pay'],$valid[$k]['add_time']);
-            if(isset($invalid[$k]['productInfo'])){
-                unset($invalid[$k]['productInfo']['is_del'],$invalid[$k]['productInfo']['is_del'],$invalid[$k]['productInfo']['is_show']);
+        foreach ($invalid as $k => $cart) {
+            unset($valid[$k]['uid'], $valid[$k]['is_del'], $valid[$k]['is_new'], $valid[$k]['is_pay'], $valid[$k]['add_time']);
+            if (isset($invalid[$k]['productInfo'])) {
+                unset($invalid[$k]['productInfo']['is_del'], $invalid[$k]['productInfo']['is_del'], $invalid[$k]['productInfo']['is_show']);
             }
         }
 
-        return compact('valid','invalid');
+        return compact('valid', 'invalid');
     }
 
     /**
@@ -289,47 +312,47 @@ class StoreCart extends BaseModel
      * @param string $cartIds
      * @return array
      */
-    public static function getUserCombinationProductCartList($uid,$cartIds='')
+    public static function getUserCombinationProductCartList($uid, $cartIds = '')
     {
         $productInfoField = 'id,image,slider_image,price,cost,ot_price,vip_price,postage,mer_id,give_integral,cate_id,sales,stock,store_name,unit_name,is_show,is_del,is_postage';
         $model = new self();
         $valid = $invalid = [];
-        $model = $model->where('uid',$uid)->where('type','product')->where('is_pay',0)
-            ->where('is_del',0);
-        if($cartIds) $model->where('id','IN',$cartIds);
+        $model = $model->where('uid', $uid)->where('type', 'product')->where('is_pay', 0)
+            ->where('is_del', 0);
+        if ($cartIds) $model->where('id', 'IN', $cartIds);
         $list = $model->select()->toArray();
-        if(!count($list)) return compact('valid','invalid');
-        foreach ($list as $k=>$cart){
+        if (!count($list)) return compact('valid', 'invalid');
+        foreach ($list as $k => $cart) {
             $product = StoreProduct::field($productInfoField)
                 ->find($cart['product_id'])->toArray();
             $cart['productInfo'] = $product;
             //商品不存在
-            if(!$product){
-                $model->where('id',$cart['id'])->update(['is_del'=>1]);
-            //商品删除或无库存
-            }else if(!$product['is_show'] || $product['is_del'] || !$product['stock']){
+            if (!$product) {
+                $model->where('id', $cart['id'])->update(['is_del' => 1]);
+                //商品删除或无库存
+            } else if (!$product['is_show'] || $product['is_del'] || !$product['stock']) {
                 $invalid[] = $cart;
-            //商品属性不对应
+                //商品属性不对应
 //            }else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique'])){
 //                $invalid[] = $cart;
-            //正常商品
-            }else{
-                $cart['truePrice'] = (float)StoreCombination::where('id',$cart['combination_id'])->value('price');
-                $cart['costPrice'] = (float)StoreCombination::where('id',$cart['combination_id'])->value('cost');
-                $cart['trueStock'] = StoreCombination::where('id',$cart['combination_id'])->value('stock');
+                //正常商品
+            } else {
+                $cart['truePrice'] = (float)StoreCombination::where('id', $cart['combination_id'])->value('price');
+                $cart['costPrice'] = (float)StoreCombination::where('id', $cart['combination_id'])->value('cost');
+                $cart['trueStock'] = StoreCombination::where('id', $cart['combination_id'])->value('stock');
                 $valid[] = $cart;
             }
         }
 
-        foreach ($valid as $k=>$cart){
-            if($cart['trueStock'] < $cart['cart_num']){
+        foreach ($valid as $k => $cart) {
+            if ($cart['trueStock'] < $cart['cart_num']) {
                 $cart['cart_num'] = $cart['trueStock'];
-                $model->where('id',$cart['id'])->update(['cart_num'=>$cart['cart_num']]);
+                $model->where('id', $cart['id'])->update(['cart_num' => $cart['cart_num']]);
                 $valid[$k] = $cart;
             }
         }
 
-        return compact('valid','invalid');
+        return compact('valid', 'invalid');
     }
 
     /**
@@ -339,15 +362,16 @@ class StoreCart extends BaseModel
      */
     public static function getCartIdsProduct(array $ids)
     {
-        return self::whereIn('id',$ids)->column('product_id','id');
+        return self::whereIn('id', $ids)->column('product_id', 'id');
     }
 
     /**
-    *  获取购物车内最新一张产品图
+     *  获取购物车内最新一张产品图
      */
-    public static function getProductImage(array $cart_id){
-        return self::whereIn('a.id',$cart_id)->alias('a')->order('a.id desc')
-            ->join('store_product p','p.id = a.product_id')->value('p.image');
+    public static function getProductImage(array $cart_id)
+    {
+        return self::whereIn('a.id', $cart_id)->alias('a')->order('a.id desc')
+            ->join('store_product p', 'p.id = a.product_id')->value('p.image');
     }
 
 }

+ 205 - 0
app/models/store/StoreIntegral.php

@@ -0,0 +1,205 @@
+<?php
+/**
+ *
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/12/18
+ */
+
+namespace app\models\store;
+
+use crmeb\basic\BaseModel;
+use crmeb\services\GroupDataService;
+use app\admin\model\store\StoreProductAttrValue;
+use app\models\store\StoreProduct;
+
+/**
+ * TODO 秒杀产品Model
+ * Class StoreSeckill
+ * @package app\models\store
+ */
+class StoreIntegral extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'store_integral';
+
+    protected function getImagesAttr($value)
+    {
+        return json_decode($value, true) ?: [];
+    }
+
+    public function getDescriptionAttr($value)
+    {
+        return htmlspecialchars_decode($value);
+    }
+
+    public static function getSeckillCount()
+    {
+        return self::where('is_del', 0)->where('status', 1)->count();
+    }
+
+    /**
+     * 获取秒杀列表
+     * @param $time
+     * @param int $page
+     * @param int $limit
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function seckillList($page = 0, $limit = 20)
+    {
+//        var_dump($page);
+//        var_dump($limit);
+        if ($page) $list = self::alias('n')->join('store_product c', 'c.id=n.product_id')->where('c.is_show', 1)->where('c.is_del', 0)->where('n.is_del', 0)->where('n.status', 1)->field('n.*')->order('n.sort desc')->page($page, $limit)->select();
+        else $list = self::alias('n')->join('store_product c', 'c.id=n.product_id')->where('c.is_show', 1)->where('c.is_del', 0)->where('n.is_del', 0)->where('n.status', 1)->field('n.*')->order('sort desc')->select();
+        if ($list) return $list->hidden(['cost', 'add_time', 'is_del'])->toArray();
+        return [];
+    }
+
+    /**
+     * 获取所有秒杀产品
+     * @param string $field
+     * @return array
+     */
+    public static function getListAll($offset = 0, $limit = 10, $field = 'id,product_id,image,title,price,integral,ot_price,start_time,stop_time,stock,sales')
+    {
+        $model = self::where('is_del', 0)->where('status', 1)->where('stock', '>', 0)->field($field)
+           ->order('sort DESC,add_time DESC');
+        $model = $model->limit($offset, $limit);
+        $list = $model->select();
+        if ($list) return $list->toArray();
+        else return [];
+    }
+
+    /**
+     * 获取热门推荐的秒杀产品
+     * @param int $limit
+     * @param string $field
+     * @return array
+     */
+    public static function getHotList($limit = 0, $field = 'id,product_id,image,title,price,ot_price,start_time,stop_time,stock,integral')
+    {
+        $model = self::where('is_hot', 1)->where('is_del', 0)->where('status', 1)->where('stock', '>', 0)->field($field)
+            ->order('sort DESC,add_time DESC');
+        if ($limit) $model->limit($limit);
+        $list = $model->select();
+        if ($list) return $list->toArray();
+        else return [];
+    }
+
+    /**
+     * 获取一条秒杀产品
+     * @param $id
+     * @param string $field
+     * @return array|false|\PDOStatement|string|\think\Model
+     */
+    public static function getValidProduct($id, $field = '*')
+    {
+        $info = self::alias('n')->join('store_product c', 'c.id=n.product_id')->where('n.id', $id)->where('c.is_show', 1)->where('c.is_del', 0)->where('n.is_del', 0)->where('n.status', 1)->field('n.*,SUM(c.sales+c.ficti) as total')->find();
+        if ($info['id']) {
+            return $info;
+        } else {
+            return [];
+        }
+    }
+
+    /**
+     * 获取秒杀是否有开启
+     * @return bool
+     */
+    public static function getSeckillContStatus()
+    {
+        $count = self::where('is_del', 0)->where('status', 1)->count();
+        return $count ? true : false;
+    }
+
+    public static function initFailSeckill()
+    {
+        self::where('is_hot', 1)->where('is_del', 0)->where('status', '<>', 1)->update(['status' => '-1']);
+    }
+
+    public static function idBySimilaritySeckill($id, $limit = 4, $field = '*')
+    {
+        $list = [];
+        $productId = self::where('id', $id)->value('product_id');
+        if ($productId) {
+            $list = array_merge($list, self::where('product_id', $productId)->where('id', '<>', $id)
+                ->where('is_del', 0)->where('status', 1)->where('stock', '>', 0)
+                ->field($field)
+                ->order('sort DESC,add_time DESC')->limit($limit)->select()->toArray());
+        }
+        $limit = $limit - count($list);
+        if ($limit) {
+            $list = array_merge($list, self::getHotList($limit, $field));
+        }
+
+        return $list;
+    }
+
+    /** 获取秒杀产品库存
+     * @param $id
+     * @return mixed
+     */
+    public static function getProductStock($id)
+    {
+        return self::where('id', $id)->value('stock');
+    }
+
+    /**
+     * 获取字段值
+     * @param $id
+     * @param string $field
+     * @return mixed
+     */
+    public static function getProductField($id, $field = 'title')
+    {
+        return self::where('id', $id)->value($field);
+    }
+
+    /**
+     * 修改秒杀库存
+     * @param int $num
+     * @param int $seckillId
+     * @return bool
+     */
+    public static function decIntegralStock($num = 0, $seckillId = 0, $unique = '')
+    {
+        $product_id = self::where('id', $seckillId)->value('product_id');
+        if ($unique) {
+            $res = false !== StoreProductAttrValue::decProductAttrStock($seckillId, $unique, $num, 4);
+            $res = $res && self::where('id', $seckillId)->dec('stock', $num)->inc('sales', $num)->update();
+            $sku = StoreProductAttrValue::where('product_id', $seckillId)->where('unique', $unique)->where('type', 4)->value('suk');
+            $res = $res && StoreProductAttrValue::where('product_id', $product_id)->where('suk', $sku)->where('type', 0)->dec('stock', $num)->inc('sales', $num)->update();
+        } else {
+            $res = false !== self::where('id', $seckillId)->dec('stock', $num)->inc('sales', $num)->update();
+        }
+        $res = $res && StoreProduct::where('id', $product_id)->dec('stock', $num)->inc('sales', $num)->update();
+        return $res;
+    }
+
+    /**
+     * 增加库存较少销量
+     * @param int $num
+     * @param int $seckillId
+     * @return bool
+     */
+    public static function incSeckillStock($num = 0, $seckillId = 0)
+    {
+        $seckill = self::where('id', $seckillId)->field(['stock', 'sales'])->find();
+        if (!$seckill) return true;
+        if ($seckill->sales > 0) $seckill->sales = bcsub($seckill->sales, $num, 0);
+        if ($seckill->sales < 0) $seckill->sales = 0;
+        $seckill->stock = bcadd($seckill->stock, $num, 0);
+        return $seckill->save();
+    }
+}

+ 62 - 31
app/models/store/StoreOrder.php

@@ -77,8 +77,10 @@ class StoreOrder extends BaseModel
     {
         $storeFreePostage = floatval(sys_config('store_free_postage')) ?: 0;//满额包邮
         $totalPrice = self::getOrderSumPrice($cartInfo, 'truePrice');//获取订单总金额
+        $totalIntegral = self::getOrderSumPrice($cartInfo, 'integral');//获取订单总金额
         $costPrice = self::getOrderSumPrice($cartInfo, 'costPrice');//获取订单成本价
         $vipPrice = self::getOrderSumPrice($cartInfo, 'vip_truePrice');//获取订单会员优惠金额
+        $totalDeposit = self::getOrderSumPrice($cartInfo, 'deposit');//获取订单会员优惠金额
         //如果满额包邮等于0
         if (!$storeFreePostage) {
             $storePostage = 0;
@@ -148,7 +150,7 @@ class StoreOrder extends BaseModel
             }
             if ($storeFreePostage <= $totalPrice) $storePostage = 0;//如果总价大于等于满额包邮 邮费等于0
         }
-        return compact('storePostage', 'storeFreePostage', 'totalPrice', 'costPrice', 'vipPrice');
+        return compact('totalDeposit', 'storePostage', 'storeFreePostage', 'totalPrice', 'costPrice', 'vipPrice', 'totalIntegral');
     }
 
 
@@ -274,7 +276,7 @@ class StoreOrder extends BaseModel
      * @throws \think\exception\DbException
      */
 
-    public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0)
+    public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $integral_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0)
     {
         self::beginTrans();
         try {
@@ -291,6 +293,8 @@ class StoreOrder extends BaseModel
             $priceGroup = $cartGroup['priceGroup'];
             $other = $cartGroup['other'];
             $payPrice = (float)$priceGroup['totalPrice'];
+            $usedIntegral = (float)$priceGroup['totalIntegral'];
+            $deposit = (float)$priceGroup['totalDeposit'];
             $addr = UserAddress::where('uid', $uid)->where('id', $addressId)->find();
             if ($payType == 'offline' && sys_config('offline_postage') == 1) {
                 $payPostage = 0;
@@ -311,6 +315,9 @@ class StoreOrder extends BaseModel
                 $addressInfo['detail'] = '';
             }
 
+            if (!$storeId && !$test) return self::setErrorInfo('请选择下单门店!', true);
+            if (!SystemStore::verificWhere()->find($storeId) && !$test) return self::setErrorInfo('请选择正确的下单门店!', true);
+
             $cartIds = [];
             $totalNum = 0;
             $gainIntegral = 0;
@@ -320,10 +327,11 @@ class StoreOrder extends BaseModel
                 if (!$seckill_id) $seckill_id = $cart['seckill_id'];
                 if (!$bargain_id) $bargain_id = $cart['bargain_id'];
                 if (!$combinationId) $combinationId = $cart['combination_id'];
+                if (!$integral_id) $integral_id = $cart['integral_id'];
                 $cartInfoGainIntegral = isset($cart['productInfo']['give_integral']) ? bcmul($cart['cart_num'], $cart['productInfo']['give_integral'], 2) : 0;
                 $gainIntegral = bcadd($gainIntegral, $cartInfoGainIntegral, 2);
             }
-            $deduction = $seckill_id || $bargain_id || $combinationId;
+            $deduction = $seckill_id || $bargain_id || $combinationId || $integral_id;
             if ($deduction) {
                 $couponId = 0;
                 $useIntegral = false;
@@ -332,7 +340,7 @@ class StoreOrder extends BaseModel
                     if (!array_key_exists($payType, self::$payType)) return self::setErrorInfo('营销产品不能使用线下支付!', true);
                 }
             }
-            //使用优惠劵
+//使用优惠劵
             $res1 = true;
             if ($couponId) {
                 $couponInfo = StoreCouponUser::validAddressWhere()->where('id', $couponId)->where('uid', $uid)->find();
@@ -356,7 +364,7 @@ class StoreOrder extends BaseModel
             }
             if (!$res1) return self::setErrorInfo('使用优惠劵失败!', true);
 
-            //$shipping_type = 1 快递发货 $shipping_type = 2 门店自提
+//$shipping_type = 1 快递发货 $shipping_type = 2 门店自提
             $store_self_mention = sys_config('store_self_mention') ?? 0;
             if (!$store_self_mention) $shipping_type = 1;
             if ($shipping_type === 1) {
@@ -367,32 +375,46 @@ class StoreOrder extends BaseModel
                 //门店自提没有邮费支付
                 $priceGroup['storePostage'] = 0;
                 $payPostage = 0;
-                if (!$storeId && !$test) {
-                    return self::setErrorInfo('请选择门店', true);
-                }
+//                if (!$storeId && !$test) {
+//                    return self::setErrorInfo('请选择门店', true);
+//                }
             }
 
-            //积分抵扣
+
             $res2 = true;
-            $SurplusIntegral = 0;
-            if ($useIntegral && $userInfo['integral'] > 0) {
-                $deductionPrice = (float)bcmul($userInfo['integral'], $other['integralRatio'], 2);
+            //积分商品
+            $SurplusIntegral = $userInfo['integral'];
+            if ($usedIntegral > 0) {
+                if ($usedIntegral > $userInfo['integral']) {
+                    return self::setErrorInfo('积分不足', true);
+                } else {
+                    $SurplusIntegral -= $usedIntegral;
+                    $res2 = $res2 && User::bcDec($userInfo['uid'], 'integral', $usedIntegral, 'uid');
+                    $res2 = $res2 && false != UserBill::expend('积分商品兑换', $uid, 'integral', 'exchange', $usedIntegral, $key, bcsub($userInfo['integral'], $usedIntegral), '购买积分商品使用' . floatval($usedIntegral) . '积分');
+                }
+            }
+//积分抵扣
+
+            if ($useIntegral && bcsub($userInfo['integral'], $usedIntegral) > 0) {
+                $deductionPrice = (float)bcmul(bcsub($userInfo['integral'], $usedIntegral), $other['integralRatio'], 2);
                 if ($deductionPrice < $payPrice) {
                     $payPrice = bcsub($payPrice, $deductionPrice, 2);
+                    $usedIntegral2 = bcsub($userInfo['integral'], $usedIntegral);
                     $usedIntegral = $userInfo['integral'];
                     $SurplusIntegral = 0;
                     $res2 = false !== User::edit(['integral' => 0], $userInfo['uid'], 'uid');
                 } else {
                     $deductionPrice = $payPrice;
-                    $usedIntegral = (float)bcdiv($payPrice, $other['integralRatio'], 2);
-                    $SurplusIntegral = bcsub($userInfo['integral'], $usedIntegral, 2);
-                    $res2 = false !== User::bcDec($userInfo['uid'], 'integral', $usedIntegral, 'uid');
+                    $usedIntegral2 = (float)bcdiv($payPrice, $other['integralRatio'], 2);
+                    $usedIntegral += (float)bcdiv($payPrice, $other['integralRatio'], 2);
+                    $SurplusIntegral = bcsub($SurplusIntegral, $usedIntegral, 2);
+                    $res2 = false !== User::bcDec($userInfo['uid'], 'integral', $usedIntegral2, 'uid');
                     $payPrice = 0;
                 }
-                $res2 = $res2 && false != UserBill::expend('积分抵扣', $uid, 'integral', 'deduction', $usedIntegral, $key, $userInfo['integral'], '购买商品使用' . floatval($usedIntegral) . '积分抵扣' . floatval($deductionPrice) . '元');
+                $res2 = $res2 && false != UserBill::expend('积分抵扣', $uid, 'integral', 'deduction', $usedIntegral2, $key, $SurplusIntegral, '购买商品使用' . floatval($usedIntegral2) . '积分抵扣' . floatval($deductionPrice) . '元');
             } else {
                 $deductionPrice = 0;
-                $usedIntegral = 0;
+                $usedIntegral += 0;
             }
             if (!$res2) return self::setErrorInfo('使用积分抵扣失败!', true);
             if ($payPrice <= 0) $payPrice = 0;
@@ -405,6 +427,7 @@ class StoreOrder extends BaseModel
                     'coupon_price' => $couponPrice,
                     'deduction_price' => $deductionPrice,
                     'SurplusIntegral' => $SurplusIntegral,
+                    'deposit' => $deposit,
                 ];
             }
             $orderInfo = [
@@ -431,17 +454,21 @@ class StoreOrder extends BaseModel
                 'pink_id' => $pinkId,
                 'seckill_id' => $seckill_id,
                 'bargain_id' => $bargain_id,
+                'integral_id' => $integral_id,
                 'cost' => $priceGroup['costPrice'],
                 'is_channel' => $isChannel,
                 'add_time' => time(),
                 'unique' => $key,
                 'shipping_type' => $shipping_type,
+                'deposit' => $deposit,
+                'deposit_back' => 0,
+                'deposit_status' => 0,
             ];
-            if ($shipping_type === 2) {
-                $orderInfo['verify_code'] = self::getStoreCode();
-                $orderInfo['store_id'] = SystemStore::getStoreDispose($storeId, 'id');
-                if (!$orderInfo['store_id']) return self::setErrorInfo('暂无门店无法选择门店自提!', true);
-            }
+//            if ($shipping_type === 2) {
+            $orderInfo['verify_code'] = self::getStoreCode();
+            $orderInfo['store_id'] = SystemStore::getStoreDispose($storeId, 'id');
+            if (!$orderInfo['store_id']) return self::setErrorInfo('暂无门店无法选择门店!', true);
+//            }
             $order = self::create($orderInfo);
             if (!$order) return self::setErrorInfo('订单生成失败!', true);
             $res5 = true;
@@ -450,20 +477,22 @@ class StoreOrder extends BaseModel
                 if ($combinationId) $res5 = $res5 && StoreCombination::decCombinationStock($cart['cart_num'], $combinationId, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
                 else if ($seckill_id) $res5 = $res5 && StoreSeckill::decSeckillStock($cart['cart_num'], $seckill_id, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
                 else if ($bargain_id) $res5 = $res5 && StoreBargain::decBargainStock($cart['cart_num'], $bargain_id, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
+                else if ($integral_id) $res5 = $res5 && StoreIntegral::decIntegralStock($cart['cart_num'], $integral_id, isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
                 else $res5 = $res5 && StoreProduct::decProductStock($cart['cart_num'], $cart['productInfo']['id'], isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique'] : '');
             }
-            //保存购物车商品信息
+//保存购物车商品信息
             $res4 = false !== StoreOrderCartInfo::setCartInfo($order['id'], $cartInfo);
-            //购物车状态修改
+//购物车状态修改
             $res6 = false !== StoreCart::where('id', 'IN', $cartIds)->update(['is_pay' => 1]);
             if (!$res4 || !$res5 || !$res6) return self::setErrorInfo('订单生成失败!', true);
-            //自动设置默认地址
+//自动设置默认地址
             UserRepository::storeProductOrderCreateEbApi($order, compact('cartInfo', 'addressId'));
             self::clearCacheOrderInfo($uid, $key);
             self::commitTrans();
             StoreOrderStatus::status($order['id'], 'cache_key_create_order', '订单生成');
             return $order;
-        } catch (\PDOException $e) {
+        } catch
+        (\PDOException $e) {
             self::rollbackTrans();
             return self::setErrorInfo('生成订单时SQL执行错误错误原因:' . $e->getMessage());
         } catch (\Exception $e) {
@@ -504,6 +533,7 @@ class StoreOrder extends BaseModel
         $combinationId = $order['combination_id'];
         $seckill_id = $order['seckill_id'];
         $bargain_id = $order['bargain_id'];
+        $integral_id = $order['integral_id'];
         $res5 = true;
         $cartInfo = StoreOrderCartInfo::where('cart_id', 'in', $order['cart_id'])->select();
         foreach ($cartInfo as $cart) {
@@ -511,6 +541,7 @@ class StoreOrder extends BaseModel
             if ($combinationId) $res5 = $res5 && StoreCombination::incCombinationStock($cart['cart_info']['cart_num'], $combinationId);
             else if ($seckill_id) $res5 = $res5 && StoreSeckill::incSeckillStock($cart['cart_info']['cart_num'], $seckill_id);
             else if ($bargain_id) $res5 = $res5 && StoreBargain::incBargainStock($cart['cart_info']['cart_num'], $bargain_id);
+            else if ($integral_id) $res5 = $res5 && StoreIntegral::incSeckillStock($cart['cart_info']['cart_num'], $integral_id);
             else $res5 = $res5 && StoreProduct::incProductStock($cart['cart_info']['cart_num'], $cart['cart_info']['productInfo']['id'], isset($cart['cart_info']['productInfo']['attrInfo']) ? $cart['cart_info']['productInfo']['attrInfo']['unique'] : '');
         }
         return $res5;
@@ -650,12 +681,12 @@ class StoreOrder extends BaseModel
         if ($orderInfo['paid']) return self::setErrorInfo('该订单已支付!');
 //        if($orderInfo['pay_type'] != 'yue') return self::setErrorInfo('该订单不能使用余额支付!');
         $userInfo = User::getUserInfo($uid);
-        if ($userInfo['now_money'] < $orderInfo['pay_price'])
-            return self::setErrorInfo(['status' => 'pay_deficiency', 'msg' => '余额不足' . floatval($orderInfo['pay_price'])]);
+        if ($userInfo['now_money'] < bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2))
+            return self::setErrorInfo(['status' => 'pay_deficiency', 'msg' => '余额不足' . floatval(bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2))]);
         self::beginTrans();
 
-        $res1 = false !== User::bcDec($uid, 'now_money', $orderInfo['pay_price'], 'uid');
-        $res2 = UserBill::expend('购买商品', $uid, 'now_money', 'pay_product', $orderInfo['pay_price'], $orderInfo['id'], $userInfo['now_money'], '余额支付' . floatval($orderInfo['pay_price']) . '元购买商品');
+        $res1 = false !== User::bcDec($uid, 'now_money', bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2), 'uid');
+        $res2 = UserBill::expend('购买商品', $uid, 'now_money', 'pay_product', bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2), $orderInfo['id'], $userInfo['now_money'], '余额支付' . floatval(bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2)) . '元购买商品' . ($orderInfo['deposit'] ? "(含押金{$orderInfo['deposit']})" : ''));
         $res3 = self::paySuccess($order_id, 'yue', $formId);//余额支付成功
         try {
             PaymentRepositories::yuePayProduct($userInfo, $orderInfo);
@@ -760,7 +791,7 @@ class StoreOrder extends BaseModel
         $oid = self::where('order_id', $orderId)->value('id');
         StoreOrderStatus::status($oid, 'pay_success', '用户付款成功');
         $now_money = User::where('uid', $order['uid'])->value('now_money');
-        UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
+        UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', bcadd($order['pay_price'], $order['deposit'], 2), $order['id'], $now_money, '支付' . floatval(bcadd($order['pay_price'], $order['deposit'], 2)) . '元购买商品' . ($order['deposit'] ? "(含押金{$order['deposit']})" : ''));
         //支付成功后
         event('OrderPaySuccess', [$order, $formId]);
         $res = $res1 && $resPink && UserSpread::setSpreadSure($order['uid']) && User::backOrderBrokerage($order);

+ 1 - 0
app/models/user/User.php

@@ -288,6 +288,7 @@ class User extends BaseModel
         if (isset($orderInfo['combination_id']) && $orderInfo['combination_id']) return true;
         if (isset($orderInfo['seckill_id']) && $orderInfo['seckill_id']) return true;
         if (isset($orderInfo['bargain_id']) && $orderInfo['bargain_id']) return true;
+        if (isset($orderInfo['integral_id']) && $orderInfo['integral_id']) return true;
 
         $userInfo = User::getUserInfo($orderInfo['uid']);
         //TODO 当前用户不存在 没有上级 或者 当用用户上级时自己  直接返回

+ 6 - 6
crmeb/repositories/OrderRepository.php

@@ -33,12 +33,12 @@ class OrderRepository
             $orderInfo = $orderId;
         if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
         if ($orderInfo['paid']) exception('支付已支付!');
-        if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
+        if (bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2) <= 0) exception('该支付无需支付!');
         $openid = WechatUser::getOpenId($orderInfo['uid']);
         $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
         $site_name = sys_config('site_name');
         if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
-        return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
+        return MiniProgramService::jsPay($openid, $orderInfo['order_id'], bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2), 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
     /**
@@ -58,12 +58,12 @@ class OrderRepository
             $orderInfo = $orderId;
         if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
         if ($orderInfo['paid']) exception('支付已支付!');
-        if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
+        if (bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2) <= 0) exception('该支付无需支付!');
         $openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
         $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
         $site_name = sys_config('site_name');
         if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
-        return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
+        return WechatService::jsPay($openid, $orderInfo['order_id'], bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2), 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
     /**
@@ -83,11 +83,11 @@ class OrderRepository
             $orderInfo = $orderId;
         if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
         if ($orderInfo['paid']) exception('支付已支付!');
-        if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
+        if (bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2) <= 0) exception('该支付无需支付!');
         $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
         $site_name = sys_config('site_name');
         if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
-        return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
+        return WechatService::paymentPrepare(null, $orderInfo['order_id'], bcadd($orderInfo['pay_price'], $orderInfo['deposit'], 2), 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
     }
 
     /**

+ 1 - 1
public/install/index.php

@@ -55,7 +55,7 @@ $step = isset($_GET['step']) ? $_GET['step'] : 1;
 
 //地址
 $scriptName = !empty($_SERVER["REQUEST_URI"]) ? $scriptName = $_SERVER["REQUEST_URI"] : $scriptName = $_SERVER["PHP_SELF"];
-$rootpath = @preg_replace("/\/(I|i)nstall\/index\.php(.*)$/", "", $scriptName);
+$rootpath = @preg_replace("/\/(I|i)nstall\/index\StoreIntegralController.php(.*)$/", "", $scriptName);
 $domain = empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
 if ((int) $_SERVER['SERVER_PORT'] != 80) {
     $domain .= ":" . $_SERVER['SERVER_PORT'];

+ 1 - 1
public/install/index_sae.php

@@ -42,7 +42,7 @@ $step = isset($_GET['step']) ? $_GET['step'] : 1;
 
 //地址
 $scriptName = !empty($_SERVER["REQUEST_URI"]) ? $scriptName = $_SERVER["REQUEST_URI"] : $scriptName = $_SERVER["PHP_SELF"];
-$rootpath = @preg_replace("/\/(I|i)nstall\/index_sae\.php(.*)$/", "", $scriptName);
+$rootpath = @preg_replace("/\/(I|i)nstall\/index_sae\StoreIntegralController.php(.*)$/", "", $scriptName);
 $domain = empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
 if ((int) $_SERVER['SERVER_PORT'] != 80) {
     $domain .= ":" . $_SERVER['SERVER_PORT'];

+ 0 - 0
public/install/install.lock


+ 16 - 11
route/api/route.php

@@ -1,6 +1,7 @@
 <?php
 
 use think\facade\Route;
+
 //账号密码登录
 Route::post('login', 'AuthController/login')->name('login')
     ->middleware(\app\http\middleware\AllowOriginMiddleware::class);
@@ -44,7 +45,8 @@ Route::group(function () {
     Route::get('admin/order/time', 'admin.StoreOrderController/time')->name('adminOrderTime');//订单交易额时间统计
     Route::post('admin/order/offline', 'admin.StoreOrderController/offline')->name('adminOrderOffline');//订单支付
     Route::post('admin/order/refund', 'admin.StoreOrderController/refund')->name('adminOrderRefund');//订单退款
-    Route::post('order/order_verific','admin.StoreOrderController/order_verific')->name('order');//订单核销
+    Route::post('admin/order/back_deposit', 'admin.StoreOrderController/back_deposit')->name('adminOrderBackDeposit');//退押金
+    Route::post('order/order_verific', 'admin.StoreOrderController/order_verific')->name('order');//订单核销
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true)->middleware(\app\http\middleware\CustomerMiddleware::class);
 
 //会员授权接口
@@ -56,7 +58,7 @@ Route::group(function () {
     //产品类
     Route::get('product/code/:id', 'store.StoreProductController/code')->name('productCode');//产品分享二维码 推广员
     Route::post('product/poster', 'store.StoreProductController/poster')->name('productPost');//产品分享海报
-     //公共类
+    //公共类
     Route::post('upload/image', 'PublicController/upload_image')->name('uploadImage');//图片上传
     //用户类 客服聊天记录
     Route::get('user/service/list', 'user.StoreService/lst')->name('userServiceList');//客服列表
@@ -81,8 +83,8 @@ Route::group(function () {
     Route::post('collect/del', 'user.UserController/collect_del')->name('collectDel');//取消收藏
     Route::post('collect/all', 'user.UserController/collect_all')->name('collectAll');//批量添加收藏
 
-    Route::get('brokerage_rank','user.UserController/brokerage_rank')->name('brokerageRank');//佣金排行
-    Route::get('rank','user.UserController/rank')->name('rank');//推广人排行
+    Route::get('brokerage_rank', 'user.UserController/brokerage_rank')->name('brokerageRank');//佣金排行
+    Route::get('rank', 'user.UserController/rank')->name('rank');//推广人排行
     //用戶类 分享
     Route::post('user/share', 'PublicController/user_share')->name('user_share');//记录用户分享
     //用户类 点赞
@@ -152,7 +154,7 @@ Route::group(function () {
     //充值类
     Route::post('recharge/routine', 'user.UserRechargeController/routine')->name('rechargeRoutine');//小程序充值
     Route::post('recharge/wechat', 'user.UserRechargeController/wechat')->name('rechargeWechat');//公众号充值
-    Route::get('recharge/index','user.UserRechargeController/index')->name('rechargeQuota');//充值余额选择
+    Route::get('recharge/index', 'user.UserRechargeController/index')->name('rechargeQuota');//充值余额选择
     //会员等级类
     Route::get('menu/user', 'PublicController/menu_user')->name('menuUser');//个人中心菜单
     Route::get('user/level/detection', 'user.UserLevelController/detection')->name('userLevelDetection');//检测用户是否可以成为会员
@@ -188,6 +190,9 @@ Route::group(function () {
     Route::get('seckill/index', 'activity.StoreSeckillController/index')->name('seckillIndex');//秒杀产品时间区间
     Route::get('seckill/list/:time', 'activity.StoreSeckillController/lst')->name('seckillList');//秒杀产品列表
     Route::get('seckill/detail/:id/[:time]', 'activity.StoreSeckillController/detail')->name('seckillDetail');//秒杀产品详情
+    //活动---积分
+    Route::get('store_integral/list', 'activity.StoreIntegralController/lst')->name('integralList');//积分产品列表
+    Route::get('store_integral/detail/:id', 'activity.StoreIntegralController/detail')->name('integralDetail');//积分产品详情
     //活动---砍价
     Route::get('bargain/config', 'activity.StoreBargainController/config')->name('bargainConfig');//砍价产品列表配置
     Route::get('bargain/list', 'activity.StoreBargainController/lst')->name('bargainList');//砍价产品列表
@@ -221,7 +226,7 @@ Route::group(function () {
     Route::post('sms/pay/notify', 'PublicController/sms_pay_notify')->name('smsPayNotify'); //短信购买异步通知
 
     //获取关注微信公众号海报
-    Route::get('wechat/follow','wechat.WechatController/follow')->name('Follow');
+    Route::get('wechat/follow', 'wechat.WechatController/follow')->name('Follow');
 
     //门店列表
     Route::get('store_list', 'PublicController/store_list')->name('storeList');
@@ -232,12 +237,12 @@ Route::group(function () {
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, false);
 
 
-Route::miss(function() {
-    if(app()->request->isOptions())
+Route::miss(function () {
+    if (app()->request->isOptions())
         return \think\Response::create('ok')->code(200)->header([
-            'Access-Control-Allow-Origin'   => '*',
-            'Access-Control-Allow-Headers'  => 'Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
-            'Access-Control-Allow-Methods'  => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
+            'Access-Control-Allow-Origin' => '*',
+            'Access-Control-Allow-Headers' => 'Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
+            'Access-Control-Allow-Methods' => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
         ]);
     else
         return \think\Response::create()->code(404);