Browse Source

商品列表,订单列表更新

goldzhang814 1 năm trước cách đây
mục cha
commit
2794d0c4c6

+ 3 - 1
app/api/controller/Checkout.php

@@ -36,6 +36,7 @@ use think\facade\Db;
 use app\api\model\groupbuylb\GroupBuyLbJoin;
 use app\api\model\order\GroupBuyLbPay;
 use app\common\model\PushLog;
+use app\common\model\store\Setting as SettingModel;
 use app\api\model\za\{ZaActivityRelation,ZaActivityGood};
 
 
@@ -135,7 +136,8 @@ class Checkout extends Controller
         }
 
         //金钱和积分的兑换比例 todo
-        if ($this->user['accumulate_points'] < bcmul($orderInfo['orderTotalPrice'] , "100",0)) {
+        $rate = SettingModel::getItem('points_rate')['points_2_money'];
+        if ($this->user['accumulate_points'] < bcmul($orderInfo['orderTotalPrice'] , $rate,0)) {
             return $this->renderError('积分不足哦', ['is_created' => false]);
         }
             // 创建订单

+ 3 - 1
app/api/controller/Goods.php

@@ -27,6 +27,7 @@ use app\api\model\groupbuylb\GroupBuyLbActivity;
 use app\common\model\ms\MsActivity as MsActivityModel;
 use app\api\model\Order as OrderModel;
 use app\api\model\za\ZaActivity as ZaActivityModel;
+use app\common\model\store\Setting as SettingModel;
 
 
 /**
@@ -46,7 +47,8 @@ class Goods extends Controller
     {
         // 获取列表数据
         $model = new GoodsModel;
-        $list = $model->getList($this->request->param());
+        $enableExchange = boolval($this->request->param('enable_exchange', 0));
+        $list = $model->getList($this->request->param(),15,false, $enableExchange);
         $goodsType = $this->request->param('goods_type', null);
         foreach ($list as $item){
             if ($goodsType == GoodsType::EXCHANGE){

+ 2 - 1
app/api/controller/Order.php

@@ -168,8 +168,9 @@ class Order extends Controller
      */
     public function list(string $dataType)
     {
+        $isExchange = boolval($this->request->param('isExchange',0));
         $model = new OrderModel;
-        $list = $model->getList($dataType);
+        $list = $model->getList($dataType,$isExchange);
         $orderService = new OrderService;
         //获取多个物流的最新信息
         $orderService->setUserOrder($list);

+ 2 - 2
app/api/model/Goods.php

@@ -79,12 +79,12 @@ class Goods extends GoodsModel
      * @return mixed|\think\model\Collection|\think\Paginator
      * @throws \think\db\exception\DbException
      */
-    public function getList(array $param = [], int $listRows = 15 , bool $showVip = false)
+    public function getList(array $param = [], int $listRows = 15 , bool $showVip = false,bool $enableExchange = false)
     {
         // 整理查询参数
         $params = array_merge($param, ['status' => GoodsStatusEnum::ON_SALE]);
         // 获取商品列表
-        $list = parent::getListFront($params, $listRows ,$showVip);
+        $list = parent::getListFront($params, $listRows ,$showVip,$enableExchange);
         if ($list->isEmpty()) {
             return $list;
         }

+ 6 - 1
app/api/model/Order.php

@@ -24,6 +24,7 @@ use app\api\service\User as UserService;
 use app\api\service\Payment as PaymentService;
 use app\api\service\order\PaySuccess as OrderPaySuccesService;
 use app\api\service\order\source\Factory as OrderSourceFactory;
+use app\common\enum\order\PayType;
 use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
 use app\common\model\Order as OrderModel;
 use app\common\service\Order as OrderService;
@@ -707,11 +708,12 @@ class Order extends OrderModel
     /**
      * 获取用户订单列表
      * @param string $type 订单类型 (all全部 payment待付款 delivery待发货 received待收货 completed已完成 comment待评价)
+     * @param boolean $isExchange 是否积分兑换订单
      * @return \think\Paginator
      * @throws BaseException
      * @throws \think\db\exception\DbException
      */
-    public function getList($type = 'all')
+    public function getList($type = 'all',$isExchange = false)
     {
 /*        // 筛选条件
         $filter = [];
@@ -745,6 +747,9 @@ class Order extends OrderModel
         }*/
 
         $filter = $this->getFilter($type);
+        if ($isExchange){
+            $filter['pay_type'] = PayType::EXCHANGE;
+        }
         // 当前用户ID
         $userId = UserService::getCurrentLoginUserId();
         // 查询列表数据

+ 5 - 3
app/api/service/order/PaySuccess.php

@@ -26,6 +26,7 @@ use app\common\enum\OrderType as OrderTypeEnum;
 use app\common\enum\order\PayType as OrderPayTypeEnum;
 use app\common\enum\user\balanceLog\Scene as SceneEnum;
 use app\common\enum\order\OrderSource as OrderSourceEnum;
+use app\common\model\store\Setting as SettingModel;
 use think\facade\Event;
 
 /**
@@ -101,7 +102,7 @@ class PaySuccess extends BaseService
             }
         }
 
-        //积分不足 todo 补充积分兑换商品比例
+        //积分不足
         if ($payType == OrderPayTypeEnum::EXCHANGE) {
             if ($this->user['accumulate_points'] < $this->model['total_price']) {
                 $this->error = '用户积分不足,无法兑换成功';
@@ -110,8 +111,9 @@ class PaySuccess extends BaseService
             $this->model->transaction(function () use ($payType, $payData) {
                 // 更新订单状态
                 $this->updateOrderInfo($payType, $payData);
-                //扣除用户积分 todo 确定积分兑换商品金额比例
-                $points = bcmul($this->model['total_price'],"100",0);
+                //扣除用户积分
+                $rate = SettingModel::getItem('points_rate')['points_2_money'];
+                $points = bcmul($this->model['total_price'],$rate,0);
                 UserModel::setDecAccumulatePoints($this->user['user_id'], $points,AccumulatePointsScene::CONSUME,'兑换商品');
                 // 记录订单支付信息
                 $this->updatePayInfo($payType);

+ 14 - 1
app/common/model/Goods.php

@@ -20,6 +20,8 @@ use app\common\library\helper;
 use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel;
 use app\common\enum\goods\Status as GoodsStatusEnum;
 use app\common\model\chef\ChefAreas as RegionModel;
+use app\common\model\store\Setting as SettingModel;
+use app\api\service\User as UserService;
 use think\facade\Db;
 
 /**
@@ -275,10 +277,12 @@ class Goods extends BaseModel
      * @param array $param 查询条件
      * @param int $listRows 分页数量
      * @param bool $showVip 会员商品列表
+     * @param bool $enableExchange 我能兑换
+     * @param string $userPonitsMoney 我能兑换
      * @return mixed
      * @throws \think\db\exception\DbException
      */
-    public function getListFront(array $param = [], int $listRows = 15,bool $showVip = false)
+    public function getListFront(array $param = [], int $listRows = 15,bool $showVip = false,$enableExchange = false)
     {
         // 筛选条件
         $query = $this->getQueryFilter($param);
@@ -298,6 +302,15 @@ class Goods extends BaseModel
         if ($showVip){
             $list = $list->whereExists('select id from yoshop_member_goods where goods_id=goods.goods_id and status=0');
         }
+
+        if ($enableExchange){
+            $user = UserService::getCurrentLoginUser();
+            $rate = SettingModel::getItem('points_rate')['points_2_money'];
+            //dd($rate);
+            $pointsToMoney = bcdiv($user['accumulate_points'], $rate, 2);
+            dd($pointsToMoney);
+            $list = $list->where('goods_price_min','<',$pointsToMoney);
+        }
         $list = $list->field($this->getAliasFields($this->name, ['content']))
             ->where('is_delete', '=', 0)
             ->where('is_show', '=', 1)

+ 2 - 0
database/store-backup/lachang.sql

@@ -0,0 +1,2 @@
+/** 用户表新增用户积分字段**/
+alter table add column `accumulate_points` int NOT NULL default "0" COMMENT "用户积分";