Card.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use crmeb\services\{JsonService as Json, FormBuilder as Form};
  5. use crmeb\services\UtilService as Util;
  6. use app\models\system\{Card as CardModel,CardInfo};
  7. use think\facade\Route as Url;
  8. class Card extends AuthController
  9. {
  10. public function index()
  11. {
  12. $this->assign([
  13. 'key' => $this->request->get('key', ''),
  14. 'type' => $this->request->param('type', ''),
  15. ]);
  16. return $this->fetch();
  17. }
  18. public function lst()
  19. {
  20. $where = Util::getMore([
  21. ['status', -1],
  22. ['key', $this->request->param('key', '')],
  23. ['data', ''],
  24. ['type', -1],
  25. ['page', 1],
  26. ['limit', 20],
  27. ['excel', 0]
  28. ]);
  29. return Json::successlayui(CardModel::lst($where));
  30. }
  31. public function create()
  32. {
  33. $f = [];
  34. $f[] = Form::input('title', '批次名称');
  35. $f[] = Form::number('totle_num', '生成数量', 500);
  36. $f[] = Form::number('amount', '卡券金额');
  37. $f[] = Form::textarea('remark','备注');
  38. $f[] = Form::hidden('status',1);
  39. $f[] = Form::radio('type','卡券类型',0)->options([['label'=>'充值卡','value'=>1],['label'=>'会员卡','value'=>0]]);
  40. $form = Form::make_post_form('修改订单', $f, Url::buildUrl('save'));
  41. $this->assign(compact('form'));
  42. return $this->fetch('public/form-builder');
  43. }
  44. public function edit($id)
  45. {
  46. if (!$id) return $this->failed('数据不存在');
  47. $product = CardModel::find($id);
  48. if (!$product) return Json::fail('数据不存在!');
  49. $f = [];
  50. $f[] = Form::input('title', '批次名称',$product->title)->disabled(true);
  51. $f[] = Form::number('amount', '卡券金额')->disabled(true);
  52. $f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
  53. $form = Form::make_post_form('修改订单', $f, Url::buildUrl('update',['id'=>$id]));
  54. $this->assign(compact('form'));
  55. return $this->fetch('public/form-builder');
  56. }
  57. public function save()
  58. {
  59. $data = Util::postMore([
  60. ['title',''],
  61. ['totle_num',0],
  62. ['amount',0],
  63. ['remark',''],
  64. ['status',1],
  65. ['type',0],
  66. ]);
  67. if(!CardModel::do_create($data))
  68. {
  69. return Json::fail(CardModel::getErrorInfo());
  70. }
  71. return Json::successful('生成成功!');
  72. }
  73. public function update($id)
  74. {
  75. if (!$id) return $this->failed('数据不存在');
  76. $product = CardModel::find($id);
  77. if (!$product) return Json::fail('数据不存在!');
  78. $status = input('post.status',0);
  79. if($product->status <>1)
  80. {
  81. return Json::fail('非正常状态不可修改');
  82. }
  83. CardModel::where('id',$id)->update(['status'=>$status]);
  84. CardInfo::where('card_id',$id)->update(['status'=>1]);
  85. return Json::successful('修改完成!');
  86. }
  87. public function info()
  88. {
  89. $this->assign([
  90. 'key' => $this->request->get('key', ''),
  91. 'type' => $this->request->param('type', ''),
  92. ]);
  93. return $this->fetch();
  94. }
  95. public function excal($id)
  96. {
  97. $where = Util::getMore([
  98. ['status', 0],
  99. ['card_id',$id],
  100. ['page', 1],
  101. ['limit', 20],
  102. ['excel', 1]
  103. ]);
  104. return CardInfo::lst($where);
  105. }
  106. public function info_lst()
  107. {
  108. $where = Util::getMore([
  109. ['status', 0],
  110. ['key', $this->request->param('key', '')],
  111. ['data', ''],
  112. ['type', -1],
  113. ['page', 1],
  114. ['limit', 20],
  115. ['excel', 0]
  116. ]);
  117. return Json::successlayui(CardInfo::lst($where));
  118. }
  119. public function use_card()
  120. {
  121. $this->assign([
  122. 'key' => $this->request->get('key', ''),
  123. 'type' => $this->request->param('type', ''),
  124. ]);
  125. return $this->fetch();
  126. }
  127. public function use_card_lst()
  128. {
  129. $where = Util::getMore([
  130. ['status', 1],
  131. ['key', $this->request->param('key', '')],
  132. ['data', ''],
  133. ['type', -1],
  134. ['page', 1],
  135. ['limit', 20],
  136. ['excel', 0]
  137. ]);
  138. return Json::successlayui(CardInfo::lst($where));
  139. }
  140. }