afa 6 months ago
parent
commit
6d58ef9dca

+ 28 - 11
application/admin/controller/user/Userpledge.php

@@ -3,11 +3,14 @@
 namespace app\admin\controller\user;
 
 use app\common\controller\Backend;
-use app\common\model\ProductLists;
+use app\common\model\ProductOrder;
 use think\exception\DbException;
-use think\response\Json;
+use app\common\model\UserPledge as UserPledgeModel;
 use Exception;
 use think\Db;
+use fast\Asset;
+use think\Loader;
+use app\common\model\LedgerTeacChangeModel;
 use think\exception\PDOException;
 use think\exception\ValidateException;
 
@@ -103,14 +106,6 @@ class Userpledge extends Backend
             $this->view->assign('row', $row);
             return $this->view->fetch();
         }
-        $params = $this->request->post('row/a');
-        if (empty($params)) {
-            $this->error(__('Parameter %s can not be empty', ''));
-        }
-        if ($params['type_id'] == '1' && strpos($params['product_id'] , ',') !== false) {
-            $this->error(__('单品只能选择一个质押产品'));
-        }
-        $params = $this->preExcludeFields($params);
         $result = false;
         Db::startTrans();
         try {
@@ -120,7 +115,29 @@ class Userpledge extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                 $row->validateFailException()->validate($validate);
             }
-            $result = $row->allowField(true)->save($params);
+
+            $rows   = $this->model::alias('a')
+                    ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
+                    ->where('a.id', $ids)->where('a.status', UserPledgeModel::Ongoing)
+                    ->field('a.*,b.day_num')
+                    ->find();
+            if(empty($rows))  throw new Exception('暂无质押订单');
+            $day   = 86400;
+            $total = 0; //当前累计收益
+            $time  = time();
+            $reta  = bcdiv($rows->day_num, $day, 6); //天数
+            $inter = ($rows->last_time == 0) ? $time - $rows->create_time: $time - $rows->last_time; //最后收取时间
+            $total = bcmul($reta, $inter, 6) * $rows->num; //累计收益
+            $rows->total_self= bcadd($total, $rows->total_self, 6);
+    
+            //修改状态
+            $detail =json_decode($rows->details, true);
+            ProductOrder::whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
+
+            Loader::model('LedgerWalletModel')->changeWalletAccount($rows->user_id, Asset::TEAC, $total, LedgerTeacChangeModel::Pledge, 0); 
+            $rows->last_time = $time;
+            $rows->status = UserPledgeModel::Close;
+            $result = $rows->save();
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();

+ 9 - 4
public/assets/js/backend/user/userpledge.js

@@ -35,11 +35,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         { field: 'operate', title: __('Operate'),
                             buttons:[
                                 {
-                                    classname: 'btn btn-xs btn-danger btn-dialog',
-                                    name: '取消详情',
-                                    text: __('取消详情'),
-                                    title: __('取消详情'),
+                                    classname: 'btn btn-xs btn-danger btn-ajax',
+                                    name: '取消存储',
+                                    text: __('取消存储'),
+                                    title: __('取消存储'),
                                     url: 'user/userpledge/cancel',
+                                    visible: function (row) {
+                                        // 自定义按钮 动态是否显示
+                                        return row.status ==1;
+                                    },
+                                    refresh:true,
                                 },
                                 {
                                     classname: 'btn btn-xs btn-info btn-dialog',