| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace app\admin\controller\trade;
- use app\common\model\Users;
- use think\Db;
- use Exception;
- use app\common\controller\Backend;
- use app\common\model\MoneyLog;
- use think\exception\DbException;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- /**
- * 充值记录管理
- *
- * @icon fa fa-circle-o
- */
- class MoneyIn extends Backend
- {
- /**
- * Mongyin模型对象
- * @var \app\admin\model\trade\Mongyin
- */
- protected $model = null;
- protected $mapType = null;
- protected $relationSearch = true;
- public function _initialize()
- {
- parent::_initialize();
- $this->mapType = array();
- $this->model = new \app\common\model\MoneyIn;
- $this->assign('typeList', $this->model->getTypeList());
- }
- /**
- * 查看
- * @return string|Json
- * @throws \think\Exception
- * @throws DbException
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- //tab
- $type = $this->request->param('order_type/d');
- if($type > 0) $this->mapType['order_type'] = $type;
-
- $list = $this->model->with('users,admins')
- ->where($where)
- ->where($this->mapType)
- ->order($sort, $order)
- ->paginate($limit);
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- /**
- * 充值订单审核
- * @param $ids
- * @return string
- * @throws DbException
- * @throws \think\Exception
- */
- public function review($ids = null, $status= 0)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $result = false;
- Db::startTrans();
- try {
- //充值
- if ($status == $this->model::Success) {
- (new MoneyLog())->change($row->user_id, $row->amount, MoneyLog::Recharge, '', '充值');
- $user_info = (new Users())->where('id', $row->user_id)->find();
- if($user_info && $user_info['freeze'] < 0){
- //卡单中,充值时消除卡单状态
- $freeze = ($row->amount + $user_info['freeze']) >= 0 ? 0 : ($row->amount + $user_info['freeze']);
- (new Users())->where('id', $user_info['id'])->update(['freeze' => $freeze]);
- }
- }
- $result = $row->allowField(true)->save(['status' => $status, 'admin_id'=>$this->auth->id]);
- //累积充值金额
- //(new Users())->where('id', $row->user_id)->setInc('money_in_sum', $row->amount);
- Db::commit();
- } catch (ValidateException|PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- }
|