UserOrdersController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace App\Admin\Controllers\UserManagement\BmUser;
  3. use App\Admin\Actions\backstage\Orders\OrderOpinion;
  4. use App\Admin\Actions\backstage\Orders\ServicePack;
  5. use App\Models\Order;
  6. use Encore\Admin\Controllers\AdminController;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Show;
  10. class UserOrdersController extends AdminController
  11. {
  12. /**
  13. * Title for current resource.
  14. *
  15. * @var string
  16. */
  17. protected $title = '订单数据总览';
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $grid = new Grid(new Order());
  26. $uesr_id = \request('user_id');
  27. $grid->filter(function ($filter){
  28. $filter->disableIdFilter();
  29. $filter->equal('user_id','用户id');
  30. });
  31. $grid->actions(function ($actions){
  32. $actions->disableView();
  33. $actions->disableEdit();
  34. $actions->disableDelete();
  35. $actions->add(new OrderOpinion());
  36. });
  37. $grid->model()->where('user_id',$uesr_id)->orderBy('id','desc');
  38. $grid->column('id', __('Id'))->sortable();
  39. $grid->column('user_id', __('用户id'))->sortable()->hide();
  40. $grid->column('user.nickname', __('用户姓名'));
  41. $grid->column('docter.name', __('医生姓名'));
  42. $grid->column('orderPatient.name', __('患者姓名'));
  43. $grid->column('orderPatient.patient_phone', __('患者电话'));
  44. $grid->column('orderPatient.appoint_start_time', __('预约日期'))->display(function ($time){
  45. if ($time == 0)
  46. {
  47. return '';
  48. }else
  49. {
  50. return date('Y-m-d H:i:s',$time);
  51. }
  52. });
  53. $grid->column('orderPatient.appoint_end_time', __('就诊日期'))->display(function ($time){
  54. if ($time == 0)
  55. {
  56. return '';
  57. }else
  58. {
  59. return date('Y-m-d H:i:s',$time);
  60. }
  61. });
  62. $grid->column('product_type', __('产品类型'))->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊预约',4=>'疫苗接种预约',5=>'儿保预约',6=>'服务包',7=>'充值']);
  63. $grid->column('payment_type', __('支付方式'))->display(function ($payment_type){
  64. if ($payment_type == 1)
  65. {
  66. return '微信支付';
  67. }
  68. if ($payment_type == 2){
  69. return '余额支付';
  70. }
  71. if ($payment_type == 3){
  72. $name = ServicePack::where('id',$this->pay_order_pack_id)->pluck('name');
  73. return '服务包支付('.$name[0].')';
  74. }
  75. return '';
  76. });
  77. $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消']);
  78. $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款']);
  79. $grid->column('total_amount', __('订单总金额'))->display(function ($money){
  80. return $money/100;
  81. });
  82. $grid->column('payment_amount', __('用户实际支付的金额'))->display(function ($money){
  83. return $money/100;
  84. });
  85. $grid->column('discount_amount', __('折扣金额'))->display(function ($money){
  86. return $money/100;
  87. });
  88. $grid->column('payment_time', __('支付时间'))->display(function ($time){
  89. if ($time == 0)
  90. {
  91. return '';
  92. }
  93. else
  94. {
  95. return date('Y-m-d H:i:s',$time);
  96. }
  97. });
  98. $grid->column('receiving_time', __('接单时间'))->display(function ($time){
  99. if ($time == 0)
  100. {
  101. return '';
  102. }
  103. else
  104. {
  105. return date('Y-m-d H:i:s',$time);
  106. }
  107. });
  108. $grid->column('end_time', __('订单完成时间'))->display(function ($time){
  109. if ($time == 0)
  110. {
  111. return '';
  112. }
  113. else
  114. {
  115. return date('Y-m-d H:i:s',$time);
  116. }
  117. });
  118. return $grid;
  119. }
  120. /**
  121. * Make a show builder.
  122. *
  123. * @param mixed $id
  124. * @return Show
  125. */
  126. protected function detail($id)
  127. {
  128. $show = new Show(Order::findOrFail($id));
  129. $show->field('id', __('Id'));
  130. $show->field('user_id', __('User id'));
  131. $show->field('docter_id', __('Docter id'));
  132. $show->field('patient_id', __('Patient id'));
  133. $show->field('organization_id', __('Organization id'));
  134. $show->field('order_sn', __('Order sn'));
  135. $show->field('payment_type', __('Payment type'));
  136. $show->field('product_type', __('Product type'));
  137. $show->field('order_status', __('Order status'));
  138. $show->field('payment_status', __('Payment status'));
  139. $show->field('total_amount', __('Total amount'));
  140. $show->field('payment_amount', __('Payment amount'));
  141. $show->field('discount_amount', __('Discount amount'));
  142. $show->field('payment_time', __('Payment time'));
  143. $show->field('end_time', __('End time'));
  144. $show->field('receiving_time', __('Receiving time'));
  145. $show->field('created_at', __('Created at'));
  146. $show->field('updated_at', __('Updated at'));
  147. return $show;
  148. }
  149. /**
  150. * Make a form builder.
  151. *
  152. * @return Form
  153. */
  154. protected function form()
  155. {
  156. $form = new Form(new Order());
  157. $form->number('user_id', __('User id'));
  158. $form->number('docter_id', __('Docter id'));
  159. $form->number('patient_id', __('Patient id'));
  160. $form->number('organization_id', __('Organization id'));
  161. $form->text('order_sn', __('Order sn'));
  162. $form->switch('payment_type', __('Payment type'))->default(1);
  163. $form->switch('product_type', __('Product type'))->default(1);
  164. $form->switch('order_status', __('Order status'))->default(1);
  165. $form->switch('payment_status', __('Payment status'))->default(1);
  166. $form->number('total_amount', __('Total amount'));
  167. $form->number('payment_amount', __('Payment amount'));
  168. $form->number('discount_amount', __('Discount amount'));
  169. $form->number('payment_time', __('Payment time'));
  170. $form->number('end_time', __('End time'));
  171. $form->number('receiving_time', __('Receiving time'));
  172. return $form;
  173. }
  174. }