model = new \app\admin\model\MobileOrder; $this->assign('status',\app\common\model\MobileOrder::$status); } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = false; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['info','operation','operation.admin']) ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row['pay_link']=request()->domain()."/build/#/oder-detail/{$row['id']}"; } $extend=[]; $extend['total']=$this->model->where($where)->sum('amount'); $extend['alipay']=$this->model->where($where)->where('pay_type',1)->sum('amount'); $extend['wechat']=$this->model->where($where)->where('pay_type',2)->sum('amount'); $extend['jd']=$this->model->where($where)->where('pay_type',3)->sum('amount'); $extend['di']=$this->model->where($where)->sum('amount_di'); $extend['profit']=$this->model->where($where)->sum('amount-amount_di'); $extend['refund']=$this->model->where($where)->sum('amount_refund'); $result = array("total" => $list->total(), "rows" => $list->items(),'extend'=>$extend); return json($result); } return $this->view->fetch(); } public function edit($ids = null) { $model=$this->model->find($ids); $row=$model->toArray(); if($this->request->isGet()){ $row['address']=$model->originData()['address']; $row['city']=\app\common\model\Area::getNameString($row['city'],'/'); $this->assign('row',$row); return view(); }else{ $data=input('row/a'); if(isset($data['city'])){ $data['city']=\app\common\model\Area::whereIn('name|shortname',str_replace('/',',',$data['city']))->column('id'); } $this->validate($data,[ 'status'=>'in:'.implode(',',array_keys(\app\common\model\MobileOrder::$status)) ]); foreach ($data as $key=>$value){ $model[$key]=$value; } $model->save(); $this->success(''); } } public function refund($ids){ $model=$this->model->find($ids); $this->assign('row',$model); if($this->request->isGet()){ return view(); }else{ $data=input('row/a'); $this->validate($data,[ 'amount|金额'=>'require|number|egt:0', ]); Db::startTrans(); $model=$this->model->where('id',$ids)->lock(true)->findOrFail(); if($data['amount']>$model['amount']){ $this->error('退款金额不能大于付款金额'); } $model['amount_refund']=$data['amount']; $model['refund_no']=session_create_id(); Refund::setType($model)->refund(); $model->save(); Db::commit(); $this->success(); } } public function status(){ return \app\common\model\MobileOrder::$status; } public function pay_type(){ return \app\common\model\MobileOrder::$payTypes; } public function add_operation(){ $id=input('ids/d'); if($this->request->isGet()){ return view(); }else{ $content=input('row.content'); $this->validate(compact('content'),[ 'content'=>'max:250', ]); MobileOrderOperation::create([ 'mobile_order_id'=>$id, 'admin_id'=>$this->auth->id, 'content'=>$content, ]); $this->success(); } } }