Couponplan.php 5.8 KB

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