作者 郭盛
1 个管道 的构建 通过 耗费 6 秒

修改后台订单模块,编写提现逻辑

... ... @@ -112,17 +112,35 @@ class Order extends Backend
$money = Db::name('order')
->alias('a')
->join('territory b','a.territory_id = b.id')
->field('a.teacher_id,a.commission,b.money')
->field('a.teacher_id,a.order_status,a.commission,b.money')
->where('a.id',$ids)
->find();
//查出老师现在有的余额
$teacher = Db::name('teacher')
->where('id',$money['teacher_id'])
->field('id,balance')
->find();
$gold = $teacher['balance'] + ($money['money'] - $money['money'] * ($money['commission']/100));
Db::name('teacher')->where('id',$money['teacher_id'])->update(['balance'=>$gold]);
}
if($money['order_status'] == 1){
//查出老师现在有的余额
$teacher = Db::name('teacher')
->where('id',$money['teacher_id'])
->field('id,balance,user_id')
->find();
$gold = $teacher['balance'] + ($money['money'] - $money['money'] * ($money['commission']/100));
Db::name('teacher')->where('id',$money['teacher_id'])->update(['balance'=>$gold]);
}else{
//查出老师现在有的余额
$teacher = Db::name('teacher')
->where('id',$money['teacher_id'])
->field('id,balance,user_id')
->find();
//添加佣金明细表
$record['money'] = $money['money'] - $money['money'] * ($money['commission']/100);
$record['type'] = 1;
$record['createtime'] = time();
$record['teacher_id'] = $money['teacher_id'];
$record['user_id'] = $teacher['user_id'];
Db::name('record')->insertGetId($record);
$gold = $teacher['balance'] + ($money['money'] - $money['money'] * ($money['commission']/100));
Db::name('teacher')->where('id',$money['teacher_id'])->update(['balance'=>$gold]);
}
}
Db::startTrans();
try {
//是否采用模型验证
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 提现管理
... ... @@ -73,4 +74,65 @@ class Withdraw extends Backend
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
if($params['status'] == 1){
$withdraw = Db::name('withdraw')->where('id',$ids)->find();
$record['createtime'] = time();
$record['user_id'] = $withdraw['user_id'];
$record['teacher_id'] = $withdraw['teacher_id'];
$record['type'] = 3;
$record['money'] = $withdraw['money'];
Db::name('record')->insertGetId($record);
}
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
... ... @@ -320,6 +320,15 @@ class Order extends Api
if($param['money'] < $money['money'] || $param['money'] > $teacher['balance']){
$this->error('提现金额有误,请重新选择');
}
//加入佣金明细
$record['createtime'] = time();
$record['type'] = 2;
$record['user_id'] = $param['user_id'];
$record['teacher_id'] = $param['teacher_id'];
$record['money'] = $param['money'];
Db::name('record')->insertGetId($record);
$param['createtime'] = time();
Db::startTrans();
$data = Db::name('withdraw')
... ... @@ -334,4 +343,42 @@ class Order extends Api
$this->error('失败');
}
}
/**
* @ApiTitle (收益记录列表)
* @ApiSummary (收益记录列表)
* @ApiMethod (POST)
* @ApiRoute (/api/order/record)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id": //id,
"teacher_id"://老师ID,
"user_id"://用户ID
"type"://类型(1订单结算2提现审核中3提现已结算)
"money"://金额
"createtime"://创建时间
}
})
*/
public function record()
{
$user_id = $this->getUserId();
$teacher = Db::name('teacher')
->where('user_id',$user_id)
->find();
$data = Db::name('record')
->where('teacher_id',$teacher['id'])
->order('createtime desc')
->select();
foreach ($data as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
}
\ No newline at end of file
... ...
此 diff 太大无法显示。