SmsQueueController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace App\Admin\Controllers\System;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\SmsQueue;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Facades\Admin;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Layout\Content;
  10. use Encore\Admin\Show;
  11. class SmsQueueController extends Controller
  12. {
  13. use HasResourceActions;
  14. /**
  15. * Index interface.
  16. *
  17. * @param Content $content
  18. * @return Content
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header('短信记录')
  24. ->description('发送记录')
  25. ->body($this->grid());
  26. }
  27. /**
  28. * Show interface.
  29. *
  30. * @param mixed $id
  31. * @param Content $content
  32. * @return Content
  33. */
  34. public function show($id, Content $content)
  35. {
  36. return $content
  37. ->header('短信记录')
  38. ->description('详细')
  39. ->body($this->detail($id));
  40. }
  41. /**
  42. * Edit interface.
  43. *
  44. * @param mixed $id
  45. * @param Content $content
  46. * @return Content
  47. */
  48. public function edit($id, Content $content)
  49. {
  50. return $content
  51. ->header('短信记录')
  52. ->description('编辑')
  53. ->body($this->form()->edit($id));
  54. }
  55. /**
  56. * Create interface.
  57. *
  58. * @param Content $content
  59. * @return Content
  60. */
  61. public function create(Content $content)
  62. {
  63. return $content
  64. ->header('短信记录')
  65. ->description('创建')
  66. ->body($this->createForm());
  67. }
  68. /**
  69. * Make a grid builder.
  70. *
  71. * @return Grid
  72. */
  73. protected function grid()
  74. {
  75. $grid = new Grid(new SmsQueue);
  76. $grid->model()->orderBy('created_at', 'desc');
  77. $grid->id('ID');
  78. $grid->column('batch.name', '批次')->width(150);
  79. $grid->utype('发送者')->display(function ($utype) {
  80. switch ($utype) {
  81. case 1:
  82. $utype = '<span class="label label-success">企业</span>';
  83. break;
  84. case 2:
  85. $utype = '<span class="label label-primary">个人</span>';
  86. break;
  87. default:
  88. $utype = '<span class="label label-default">系统</span>';
  89. break;
  90. }
  91. return $utype;
  92. });
  93. $grid->s_number('手机号')->width(150);
  94. $grid->s_body('短信内容')->width(200);
  95. $grid->s_status('状态')->display(function ($m_status) {
  96. switch ($m_status) {
  97. case 1:
  98. $m_status = '<span class="label label-success">成功</span>';
  99. break;
  100. case 2:
  101. $m_status = '<span class="label label-warning">等待</span>';
  102. break;
  103. case 3:
  104. $m_status = '<span class="label label-default">失败</span>';
  105. break;
  106. default:
  107. $m_status = '<span class="label label-warning">等待</span>';
  108. break;
  109. }
  110. return $m_status;
  111. });
  112. $grid->error_message('错误信息')->width(200);
  113. $grid->s_sendtime('发送时间');
  114. $grid->created_at('添加时间')->sortable();
  115. $grid->actions(function ($actions) use ($grid) {
  116. if (Admin::user()->can('system_sms_queue_delete')) {
  117. $actions->disableDelete(false);
  118. }
  119. });
  120. if (Admin::user()->can('system_sms_queue_delete')) {
  121. $grid->tools(function ($tools) {
  122. $tools->batch(function ($batch) {
  123. $batch->disableDelete(false);
  124. });
  125. });
  126. $grid->disableRowSelector(false);
  127. }
  128. $grid->filter(function ($filter) {
  129. $filter->equal('s_status', '状态')->select([
  130. 1 => '发送成功',
  131. 2 => '等待发送',
  132. 3 => '发送失败',
  133. ]);
  134. });
  135. $grid->tools(function ($tools) {
  136. //$tools->append('<a class="btn btn-sm btn-primary" href="/admin/sys/sms/queue/bath" title="短信推送"><i class="fa fa-save"></i><span class="hidden-xs"> 短信推送</span></a>');
  137. });
  138. return $grid;
  139. }
  140. /**
  141. * Make a show builder.
  142. *
  143. * @param mixed $id
  144. * @return Show
  145. */
  146. protected function detail($id)
  147. {
  148. $show = new Show(SmsQueue::findOrFail($id));
  149. $show->id("ID");
  150. // $show->batch('批次', function ($batch) {
  151. // $batch->name();
  152. // });
  153. $show->utype('发送者')->unescape()->as(function ($m_status) {
  154. switch ($m_status) {
  155. case 1:
  156. $m_status = '<span class="label label-success">企业</span>';
  157. break;
  158. case 2:
  159. $m_status = '<span class="label label-primary">个人</span>';
  160. break;
  161. default:
  162. $m_status = '<span class="label label-default">系统</span>';
  163. break;
  164. }
  165. return $m_status;
  166. });
  167. $show->s_number('手机号');
  168. $show->s_body('短信内容');
  169. $show->s_status('状态')->unescape()->as(function ($m_status) {
  170. switch ($m_status) {
  171. case 1:
  172. $m_status = '<span class="label label-success">成功</span>';
  173. break;
  174. case 2:
  175. $m_status = '<span class="label label-warning">等待</span>';
  176. break;
  177. case 3:
  178. $m_status = '<span class="label label-error">失败</span>';
  179. break;
  180. default:
  181. $m_status = '<span class="label label-warning">等待</span>';
  182. break;
  183. }
  184. return $m_status;
  185. });
  186. $show->error_message('错误信息');
  187. $show->s_sendtime('发送时间');
  188. $show->created_at('添加时间');
  189. return $show;
  190. }
  191. /**
  192. * Make a form builder.
  193. *
  194. * @return Form
  195. */
  196. protected function form()
  197. {
  198. $form = new Form(new SmsQueue);
  199. $form->display('ID');
  200. $form->display('Created at');
  201. $form->display('Updated at');
  202. return $form;
  203. }
  204. }