Browse Source

会员升级

Kirin 1 year ago
parent
commit
61d287ffec
2 changed files with 43 additions and 1 deletions
  1. 9 0
      app/dao/user/UserIntegralDao.php
  2. 34 1
      app/services/user/UserAwardIntegralServices.php

+ 9 - 0
app/dao/user/UserIntegralDao.php

@@ -50,4 +50,13 @@ class UserIntegralDao extends BaseDao
             $query->page($page, $limit);
         })->order('id desc')->select()->toArray();
     }
+
+    public function search(array $where = [])
+    {
+        if ($where) {
+            return $this->withSearchSelect(array_keys($where), $where);
+        } else {
+            return $this->getModel();
+        }
+    }
 }

+ 34 - 1
app/services/user/UserAwardIntegralServices.php

@@ -16,11 +16,13 @@ use app\dao\system\AwardLakeDao;
 use app\dao\user\UserIntegralDao;
 use app\model\user\UserIntegral;
 use app\services\BaseServices;
+use crmeb\services\FormBuilder;
 use crmeb\traits\ServicesTrait;
 use app\webscoket\SocketPush;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
+use think\facade\Route;
 
 /**
  *
@@ -132,6 +134,17 @@ class UserAwardIntegralServices extends BaseServices
     }
 
 
+    /**
+     * 获取单条数据
+     * @return array|\think\Model|null
+     */
+    public function getTopStaticIntegral($id)
+    {
+        $where = ['status' => 0, 'type' => 0];
+        return $this->dao->search($where)->where('id', '>', $id)->order('id', 'asc')->find();
+    }
+
+
     /**
      * 获取单条数据
      * @return float
@@ -250,7 +263,11 @@ class UserAwardIntegralServices extends BaseServices
 
     public function incUpdateIntegral(int $id, string $price, string $total, string $mark)
     {
-        $inc_integral = bcdiv($total, $price, 5);
+        if ($price > 0) {
+            $inc_integral = bcdiv($total, $price, 5);
+        } else {
+            $inc_integral = $total;
+        }
         $origin = $this->get($id);
         return $this->dao->update($id, [
             'num' => bcadd($origin['num'], $inc_integral, 5),
@@ -276,4 +293,20 @@ class UserAwardIntegralServices extends BaseServices
         ]);
     }
 
+
+    /**
+     * 获取修改页面数据
+     * @param int $id
+     * @return array
+     * @throws \FormBuilder\Exception\FormBuilderException
+     */
+    public function editLack()
+    {
+        $f = array();
+        $f[] = FormBuilder::number('num', '操作数量', 0)->step(0.01)->min(0.01)->max($this->getLake())->required();
+        $f[] = FormBuilder::radio('pm', '操作类型', 1)->options([['value' => 1, 'label' => '增加'], ['value' => 0, 'label' => '减少']]);
+        $f[] = FormBuilder::textarea('mark', '操作原因');
+        return create_form('编辑', $f, Route::buildUrl('/finance/lake'), 'POST');
+    }
+
 }