BusienssIncrementController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace App\Admin\Controllers\Company;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Order;
  5. use App\Models\Subsite;
  6. use Encore\Admin\Auth\Permission;
  7. use Encore\Admin\Controllers\HasResourceActions;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. use Encore\Admin\Show;
  12. class BusienssIncrementController extends Controller
  13. {
  14. use HasResourceActions;
  15. /**
  16. * Index interface.
  17. *
  18. * @param Content $content
  19. * @return Content
  20. */
  21. public function index(Content $content)
  22. {
  23. return $content
  24. ->header('增值服务')
  25. ->description('列表')
  26. ->body($this->grid());
  27. }
  28. /**
  29. * Show interface.
  30. *
  31. * @param mixed $id
  32. * @param Content $content
  33. * @return Content
  34. */
  35. public function show($id, Content $content)
  36. {
  37. return $content
  38. ->header('增值服务')
  39. ->description('详情')
  40. ->body($this->detail($id));
  41. }
  42. /**
  43. * Edit interface.
  44. *
  45. * @param mixed $id
  46. * @param Content $content
  47. * @return Content
  48. */
  49. public function edit($id, Content $content)
  50. {
  51. return $content
  52. ->header('增值服务')
  53. ->description('修改')
  54. ->body($this->form()->edit($id));
  55. }
  56. /**
  57. * Create interface.
  58. *
  59. * @param Content $content
  60. * @return Content
  61. */
  62. public function create(Content $content)
  63. {
  64. return $content
  65. ->header('增值服务')
  66. ->description('新增')
  67. ->body($this->form());
  68. }
  69. /**
  70. * Make a grid builder.
  71. *
  72. * @return Grid
  73. */
  74. protected function grid()
  75. {
  76. Permission::check('increment_manager_index');
  77. $grid = new Grid(new Order);
  78. $grid->model()->where('utype', 1)->whereNotIn( 'order_type', [1,2])->when(get_subsite_id()>0, function ($querys) {
  79. $querys->whereHas('companys', function ($query) {
  80. $query->where('subsite_id', get_subsite_id());
  81. });
  82. });
  83. $grid->service_name('服务内容');
  84. $grid->column('companys.companyname', '企业名称');
  85. $grid->column('companys.username', '申请会员');
  86. $grid->amount('金额');
  87. $grid->created_at('申请时间');
  88. $grid->filter(function ($filter) {
  89. //在这里添加字段过滤器
  90. $filter->equal('uid', '企业ID');
  91. $filter->like('companys.username', '会员名称');
  92. $subsite = Subsite::where('effective', 1)->select('id', 'sitename')->get();
  93. $subsiteArr=[];
  94. if ($subsite) {
  95. $subsiteArr = $subsite->toArray();
  96. $subsiteArr = array_column($subsiteArr, 'sitename', 'id');
  97. }
  98. $subsiteArr[0] = "总站";
  99. ksort($subsiteArr);
  100. if (get_subsite_id()== 0) {
  101. $filter->equal('companys.subsite_id', '所属分站')->select($subsiteArr);
  102. }
  103. //$filter->like('companys.companyname','企业名称');
  104. $filter->equal('order_type', '订单类型')->select(
  105. [
  106. 1=>'套餐升级',
  107. 2=>'充值积分',
  108. 3=>'简历置顶',
  109. 4=>'醒目标签',
  110. 5=>'简历模板',
  111. 6=>'简历包',
  112. 7=>'短信包',
  113. 8=>'职位置顶',
  114. 9=>'职位紧急',
  115. 10=>'企业模板',
  116. 11=>'职位刷新',
  117. 12=>'简历下载'
  118. ]
  119. );
  120. $filter->between('created_at', '注册时间')->datetime();
  121. });
  122. return $grid;
  123. }
  124. /**
  125. * Make a show builder.
  126. *
  127. * @param mixed $id
  128. * @return Show
  129. */
  130. protected function detail($id)
  131. {
  132. $show = new Show(Order::findOrFail($id));
  133. $show->oid('订单ID');
  134. $show->companys()->companyname('企业名称')->as(function ($companys) {
  135. return $companys->companyname;
  136. });
  137. $show->is_pay()->as(function ($is_pay) {
  138. switch ($is_pay) {
  139. case 1:
  140. return "待付款";
  141. break;
  142. case 2:
  143. return "已付款";
  144. break;
  145. case 3:
  146. return "已取消";
  147. break;
  148. }
  149. });
  150. $show->amount('订单金额');
  151. $show->pay_amount('现金支付金额');
  152. $show->pay_points('积分支付');
  153. $show->service_name('订单描述');
  154. $show->pay_type('订单金额')->as(function ($pay_type) {
  155. switch ($pay_type) {
  156. case 1:
  157. return '现金';
  158. break;
  159. case 2:
  160. return '积分';
  161. break;
  162. case 3:
  163. return '现金+积分';
  164. break;
  165. }
  166. });
  167. $show->payment_time('支付时间')->as(function ($payment_time) {
  168. if ($payment_time) {
  169. return date('Y-m-d H:i:s', $payment_time);
  170. }
  171. return '';
  172. });
  173. $show->notes('备注');
  174. return $show;
  175. }
  176. /**
  177. * Make a form builder.
  178. *
  179. * @return Form
  180. */
  181. protected function form()
  182. {
  183. $form = new Form(new Order);
  184. $form->display('id');
  185. $form->display('companys.username', '申请会员');
  186. $form->radio('is_pay', '支付状态')->options([1=>'待付款',2=>'已付款',3=>'已取消']);
  187. $form->display('amount', '订单金额');
  188. $form->display('pay_amount', '现金支付金额');
  189. $form->display('pay_points', '积分支付');
  190. $form->display('service_name', '订单描述');
  191. $form->display('pay_type', '支付方式')->with(function ($pay_type) {
  192. switch ($pay_type) {
  193. case 1:
  194. return '现金';
  195. break;
  196. case 2:
  197. return '积分';
  198. break;
  199. case 3:
  200. return '现金+积分';
  201. break;
  202. }
  203. });
  204. $form->display('oid', '订单号');
  205. $form->display('created_at', '申请时间');
  206. $form->display('payment_time', '支付时间')->with(function ($payment_time) {
  207. if ($payment_time) {
  208. return date('Y-m-d H:i:s', $payment_time);
  209. }
  210. return '';
  211. });
  212. $form->text('notes', '添加备注');
  213. return $form;
  214. }
  215. }