|
|
<?php
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
|
* User: Administrator
|
|
|
* Date: 2020/1/19
|
|
|
* Time: 14:44
|
|
|
*/
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use think\Db;
|
|
|
use app\common\controller\Backend;
|
|
|
|
|
|
class Sonorder extends Backend
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* Order模型对象
|
|
|
* @var \app\admin\model\Order
|
|
|
*/
|
|
|
protected $model = null;
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->model = new \app\admin\model\Sonorder;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
*/
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查看
|
|
|
*/
|
|
|
public function index1($ids)
|
|
|
{
|
|
|
//设置过滤方法
|
|
|
$this->request->filter(['strip_tags']);
|
|
|
if ($this->request->isAjax()) {
|
|
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
if ($this->request->request('keyField')) {
|
|
|
return $this->selectpage();
|
|
|
}
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
$total = $this->model
|
|
|
->where('order_id',$ids)
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->count();
|
|
|
|
|
|
$list = $this->model
|
|
|
->where('order_id',$ids)
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->limit($offset, $limit)
|
|
|
->select();
|
|
|
|
|
|
$list = collection($list)->toArray();
|
|
|
$result = array("total" => $total, "rows" => $list);
|
|
|
|
|
|
return json($result);
|
|
|
}
|
|
|
$this->assignconfig("order_id",$ids);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量更新
|
|
|
*/
|
|
|
public function multi($ids = "")
|
|
|
{
|
|
|
$ids = $ids ? $ids : $this->request->param("ids");
|
|
|
if ($ids) {
|
|
|
if ($this->request->has('params')) {
|
|
|
parse_str($this->request->post("params"), $values);
|
|
|
$values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
|
|
|
if ($values) {
|
|
|
$adminIds = $this->getDataLimitAdminIds();
|
|
|
if (is_array($adminIds)) {
|
|
|
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
|
}
|
|
|
$count = 0;
|
|
|
|
|
|
//查询子订单信息
|
|
|
$order = Db::name('sonorder')->where('id',$ids)->find();
|
|
|
|
|
|
//如果审核通过情况
|
|
|
if($values['order_status'] == 1){
|
|
|
|
|
|
//查询主订单信息 老师设定的金额 以及该订单的佣金比例
|
|
|
$zhu_order = Db::name('order')
|
|
|
->alias('a')
|
|
|
->join('territory b','a.territory_id = b.id')
|
|
|
->field('a.teacher_id,a.user_id,a.order_status,a.commission,b.money')
|
|
|
->where('a.id',$order['order_id'])
|
|
|
->find();
|
|
|
|
|
|
//本身状态就为1的情况
|
|
|
if($order['order_status'] != 1){
|
|
|
//查出老师现在有的余额
|
|
|
$teacher = Db::name('teacher')
|
|
|
->where('id',$zhu_order['teacher_id'])
|
|
|
->field('id,balance,user_id')
|
|
|
->find();
|
|
|
//添加佣金明细表
|
|
|
$record['money'] = $zhu_order['money'] - $zhu_order['money'] * ($zhu_order['commission']/100);
|
|
|
$record['type'] = 1;
|
|
|
$record['createtime'] = time();
|
|
|
$record['teacher_id'] = $zhu_order['teacher_id'];
|
|
|
$record['user_id'] = $zhu_order['user_id'];
|
|
|
Db::name('record')->insertGetId($record);
|
|
|
|
|
|
$gold = $teacher['balance'] + ($zhu_order['money'] - $zhu_order['money'] * ($zhu_order['commission']/100));
|
|
|
Db::name('teacher')->where('id',$zhu_order['teacher_id'])->update(['balance'=>$gold]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
|
|
|
foreach ($list as $index => $item) {
|
|
|
$count += $item->allowField(true)->isUpdate(true)->save($values);
|
|
|
}
|
|
|
Db::commit();
|
|
|
} catch (PDOException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
if ($count) {
|
|
|
$this->success();
|
|
|
} else {
|
|
|
$this->error(__('No rows were updated'));
|
|
|
}
|
|
|
} else {
|
|
|
$this->error(__('You have no permission'));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|