model = new CouponPlanModel(); } public function index () { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); $count = $this->model ->withJoin('area', 'LEFT') ->where($where) ->count(); // return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]'); $list = $this->model // ->withoutField('password') // ->withAttr('buy_time', function ($val, $data){ // $dataval = json_decode($val); // if (!$dataval){ // return '全天时间段'; // }else{ // $time = ''; // foreach ($data as $k=>$v){ // $time .= '每天'.$v['start'].'到'.$v['end']; // } // return $time; // } // // }) ->withJoin('area', 'LEFT') ->where($where) ->page($page, $limit) ->order($this->sort) ->select(); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } // /** // * @NodeAnotation(title="添加") // */ // public function add() // { // if ($this->request->isAjax()){ // $row = request()->post(); // $row['create_time'] = sr_getcurtime(time()); // unset($row['file']); // $modelplan = new CouponPlanModel(); // Db::startTrans(); // try { // $a_id = $this->model->insertGetId($row); // $modelplan->insert([ // 'area_id'=>$a_id, // 'target_num'=>$row['begin_num'], // 'create_time'=>sr_getcurtime(time()), // 'buy_least'=>1, // 'buy_most'=>1000 // ]); // Db::commit(); // }catch (\Exception $e){ // $this->error('添加失败'. $e->getMessage()); // Db::rollback(); // } // $this->success('添加成功'); // } // // return $this->fetch(); // } /** * @NodeAnotation(title="爆仓") */ public function baocang($id){ if ($this->request->isAjax()){ Db::startTrans(); try { $this->model->baocang($id); Db::commit(); }catch (\Exception $e){ Db::rollback(); $this->error($e->getMessage()); } } $this->success('成功'); } /** * @NodeAnotation(title="发放") */ public function fafang($id){ if ($this->request->isAjax()){ // 1 代表小数点后面几位 .代表小数点跟正数分割的字符 ,这个是千位的 分割 // return number_format(444567.24, 1, '.', ','); Db::startTrans(); try { $this->model->fafang($id); Db::commit(); }catch (\Exception $e){ Db::rollback(); $this->error($e->getMessage()); } } $this->success('发放成功'); } /** * @NodeAnotation(title="修改目标值") */ public function edittarget($id){ if ($this->request->isPost()) { $post = $this->request->post(); $plan_info = $this->model->where('id', $post['id'])->findOrEmpty(); $target = $post['target']; if (intval($target) < 10){ $this->error('输入目标金额错误'); } if (intval($target)%10 != 0){ $this->error('输入必须是10的整数倍'); } empty($plan_info) && $this->error('信息不存在'); if ($plan_info['status'] != 0){ $this->error('状态错误,请刷新数据'); } $this->model->startTrans(); try { $this->model->where('id', $post['id'])->save(['target_num'=>$target]); $this->model->where('id', $post['id'])->save(['less_num'=>$target-$plan_info['cur_num']]); $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('失败'.$e->getMessage()); } $this->success('成功'); } $info = Db::name('coupon_plan')->where('id', $id)->find(); $this->assign('info', $info); $area_info = Db::name('coupon_area')->where('id', $info['area_id'])->find(); $this->assign('info', $info); $this->assign('areainfo', $area_info); return $this->fetch(); } }