Couponplan.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\admin\controller\coupon;
  3. use app\admin\model\SystemAdmin;
  4. use app\common\model\CouponAreaModel;
  5. use app\common\model\CouponPlanModel;
  6. use app\common\model\ShopCategory;
  7. use app\admin\traits\Curd;
  8. use app\common\controller\AdminController;
  9. use app\common\model\ThirddataLogModel;
  10. use app\common\model\ThirddataModel;
  11. use EasyAdmin\annotation\ControllerAnnotation;
  12. use EasyAdmin\annotation\NodeAnotation;
  13. use think\App;
  14. use think\facade\Db;
  15. use think\Model;
  16. /**
  17. * Class Admin
  18. * @package app\admin\controller\system
  19. * @ControllerAnnotation(title="消费券计划管理")
  20. */
  21. class Couponplan extends AdminController
  22. {
  23. use Curd;
  24. public function __construct(App $app)
  25. {
  26. parent::__construct($app);
  27. $this->model = new CouponPlanModel();
  28. }
  29. public function index ()
  30. {
  31. if ($this->request->isAjax()) {
  32. if (input('selectFields')) {
  33. return $this->selectList();
  34. }
  35. list($page, $limit, $where) = $this->buildTableParames();
  36. $count = $this->model
  37. ->withJoin('area', 'LEFT')
  38. ->where($where)
  39. ->count();
  40. // return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
  41. $list = $this->model
  42. // ->withoutField('password')
  43. // ->withAttr('buy_time', function ($val, $data){
  44. // $dataval = json_decode($val);
  45. // if (!$dataval){
  46. // return '全天时间段';
  47. // }else{
  48. // $time = '';
  49. // foreach ($data as $k=>$v){
  50. // $time .= '每天'.$v['start'].'到'.$v['end'];
  51. // }
  52. // return $time;
  53. // }
  54. //
  55. // })
  56. ->withJoin('area', 'LEFT')
  57. ->where($where)
  58. ->page($page, $limit)
  59. ->order($this->sort)
  60. ->select();
  61. $data = [
  62. 'code' => 0,
  63. 'msg' => '',
  64. 'count' => $count,
  65. 'data' => $list,
  66. ];
  67. return json($data);
  68. }
  69. return $this->fetch();
  70. }
  71. // /**
  72. // * @NodeAnotation(title="添加")
  73. // */
  74. // public function add()
  75. // {
  76. // if ($this->request->isAjax()){
  77. // $row = request()->post();
  78. // $row['create_time'] = sr_getcurtime(time());
  79. // unset($row['file']);
  80. // $modelplan = new CouponPlanModel();
  81. // Db::startTrans();
  82. // try {
  83. // $a_id = $this->model->insertGetId($row);
  84. // $modelplan->insert([
  85. // 'area_id'=>$a_id,
  86. // 'target_num'=>$row['begin_num'],
  87. // 'create_time'=>sr_getcurtime(time()),
  88. // 'buy_least'=>1,
  89. // 'buy_most'=>1000
  90. // ]);
  91. // Db::commit();
  92. // }catch (\Exception $e){
  93. // $this->error('添加失败'. $e->getMessage());
  94. // Db::rollback();
  95. // }
  96. // $this->success('添加成功');
  97. // }
  98. //
  99. // return $this->fetch();
  100. // }
  101. /**
  102. * @NodeAnotation(title="爆仓")
  103. */
  104. public function baocang($id){
  105. if ($this->request->isAjax()){
  106. Db::startTrans();
  107. try {
  108. $this->model->baocang($id);
  109. Db::commit();
  110. }catch (\Exception $e){
  111. Db::rollback();
  112. $this->error($e->getMessage());
  113. }
  114. }
  115. $this->success('成功');
  116. }
  117. /**
  118. * @NodeAnotation(title="发放")
  119. */
  120. public function fafang($id){
  121. if ($this->request->isAjax()){
  122. // 1 代表小数点后面几位 .代表小数点跟正数分割的字符 ,这个是千位的 分割
  123. // return number_format(444567.24, 1, '.', ',');
  124. Db::startTrans();
  125. try {
  126. $this->model->fafang($id);
  127. Db::commit();
  128. }catch (\Exception $e){
  129. Db::rollback();
  130. $this->error($e->getMessage());
  131. }
  132. }
  133. $this->success('发放成功');
  134. }
  135. /**
  136. * @NodeAnotation(title="修改目标值")
  137. */
  138. public function edittarget($id){
  139. if ($this->request->isPost()) {
  140. $post = $this->request->post();
  141. $plan_info = $this->model->where('id', $post['id'])->findOrEmpty();
  142. $target = $post['target'];
  143. if (intval($target) < 10){
  144. $this->error('输入目标金额错误');
  145. }
  146. if (intval($target)%10 != 0){
  147. $this->error('输入必须是10的整数倍');
  148. }
  149. empty($plan_info) && $this->error('信息不存在');
  150. if ($plan_info['status'] != 0){
  151. $this->error('状态错误,请刷新数据');
  152. }
  153. $this->model->startTrans();
  154. try {
  155. $this->model->where('id', $post['id'])->save(['target_num'=>$target]);
  156. $this->model->where('id', $post['id'])->save(['less_num'=>$target-$plan_info['cur_num']]);
  157. $this->model->commit();
  158. } catch (\Exception $e) {
  159. $this->model->rollback();
  160. $this->error('失败'.$e->getMessage());
  161. }
  162. $this->success('成功');
  163. }
  164. $info = Db::name('coupon_plan')->where('id', $id)->find();
  165. $this->assign('info', $info);
  166. $area_info = Db::name('coupon_area')->where('id', $info['area_id'])->find();
  167. $this->assign('info', $info);
  168. $this->assign('areainfo', $area_info);
  169. return $this->fetch();
  170. }
  171. }