|
|
@@ -13,7 +13,7 @@ use think\Loader;
|
|
|
use app\common\model\LedgerTeacChangeModel;
|
|
|
use think\exception\PDOException;
|
|
|
use think\exception\ValidateException;
|
|
|
-
|
|
|
+use think\Request;
|
|
|
/**
|
|
|
* 用户存储列表 TeamRewards
|
|
|
*
|
|
|
@@ -27,12 +27,12 @@ class Userpledge extends Backend
|
|
|
* @var \app\admin\model\TeamRewards
|
|
|
*/
|
|
|
protected $model = null;
|
|
|
-
|
|
|
+ protected $product_order_model = null;
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\common\model\UserPledge;
|
|
|
-
|
|
|
+ $this->product_order_model = new \app\common\model\ProductOrder;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -57,10 +57,10 @@ class Userpledge extends Backend
|
|
|
}
|
|
|
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
|
|
$list = $this->model->with('users,pledges')
|
|
|
- ->where($where)
|
|
|
- ->order($sort, $order)
|
|
|
- ->paginate($limit);
|
|
|
-
|
|
|
+ ->where($where)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->paginate($limit);
|
|
|
+
|
|
|
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
|
|
return json($result);
|
|
|
}
|
|
|
@@ -71,19 +71,55 @@ class Userpledge extends Backend
|
|
|
*/
|
|
|
public function detail($ids)
|
|
|
{
|
|
|
+
|
|
|
$row = $this->model->get(['id' => $ids]);
|
|
|
if (!$row) {
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
+
|
|
|
if ($this->request->isAjax()) {
|
|
|
$this->success("Ajax请求成功", null, ['id' => $ids]);
|
|
|
}
|
|
|
+
|
|
|
$details = json_decode($row->details, true);
|
|
|
+
|
|
|
+ // 提取所有id,返回一个包含id的一维数组
|
|
|
+ $order_no = array_column($details, 'order_no');
|
|
|
+
|
|
|
+ $orderData = $this->product_order_model
|
|
|
+ ->where('order_no', 'in', $order_no)
|
|
|
+ ->field('order_no, status') // 指定字段
|
|
|
+ ->select();
|
|
|
+ $status_txt=['已下单','支付','转让','提货','取消','关闭','存储中'];
|
|
|
+ // 3. 合并 status 到主数据
|
|
|
+ foreach ($details as &$item_outside) {
|
|
|
+ foreach ($orderData as &$item_inside) {
|
|
|
+ if($item_outside['order_no']==$item_inside['order_no']){
|
|
|
+ $status=$item_inside['status'];
|
|
|
+ $item_outside['status']=$status;
|
|
|
+ $item_outside['status_txt']=$status_txt[$status];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $userpledge_status=$row['status'];
|
|
|
+
|
|
|
+ $this->view->assign("userpledge_status", $userpledge_status);
|
|
|
$this->view->assign("row", $details);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 取消存储
|
|
|
+ */
|
|
|
+ public function cancelStorage(){
|
|
|
+ $id = $this->request->param('id');
|
|
|
+ $resp=$this->product_order_model->where('id', $id)
|
|
|
+ ->update(['status' => 5]);
|
|
|
+ return $resp;
|
|
|
+ // $this->success('取消存储', $resp);
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* 编辑
|
|
|
*
|
|
|
@@ -117,29 +153,29 @@ class Userpledge extends Backend
|
|
|
}
|
|
|
|
|
|
$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('暂无质押订单');
|
|
|
+ ->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; //最后收取时间
|
|
|
+ $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);
|
|
|
-
|
|
|
+ $rows->total_self = bcadd($total, $rows->total_self, 6);
|
|
|
+
|
|
|
//修改状态
|
|
|
- $detail =json_decode($rows->details, true);
|
|
|
+ $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);
|
|
|
+ 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) {
|
|
|
+ } catch (ValidateException | PDOException | Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
@@ -148,5 +184,4 @@ class Userpledge extends Backend
|
|
|
}
|
|
|
$this->success();
|
|
|
}
|
|
|
-
|
|
|
}
|