| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\admin\controller\coupon;
- use app\admin\model\SystemAdmin;
- use app\common\model\CouponAreaModel;
- use app\common\model\CouponPlanModel;
- use app\common\model\ShopCategory;
- use app\admin\traits\Curd;
- use app\common\controller\AdminController;
- use app\common\model\ThirddataLogModel;
- use app\common\model\ThirddataModel;
- use EasyAdmin\annotation\ControllerAnnotation;
- use EasyAdmin\annotation\NodeAnotation;
- use think\App;
- use think\facade\Db;
- use think\Model;
- /**(业务已取消)
- * (业务已取消)
- * Class Admin
- * @package app\admin\controller\system
- * @ControllerAnnotation(title="消费券计划管理")
- */
- class Couponplan extends AdminController
- {
- use Curd;
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->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();
- }
- }
|