WriteOffController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\admin\controller\member;
  3. use app\controller\Curd;
  4. use app\model\MemberBenefit;
  5. use app\model\RuleAddedComponent;
  6. use app\model\SysUser;
  7. use support\Db;
  8. use support\Request;
  9. class WriteOffController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. // $this->model = new ;
  14. }
  15. public function list(Request $request)
  16. {
  17. $page = $request->get('page', 1);
  18. $pageSize = $request->get('pageSize', 50);
  19. $keywords = $request->get('keywords','');
  20. $userId = $request->get('user_id','');
  21. $premises = $request->get('premises','');
  22. $date = $request->get('date',[]);
  23. $appointmentList = Db::table('appointment')
  24. ->leftJoin('member','member.member_id' ,'=','appointment.join_appointment_member_id')
  25. ->leftJoin('member_cert','member_cert.join_cert_member_id' ,'=','appointment.join_appointment_member_id')
  26. ->select('appointment.appointment_id as quota_id', 'appointment.join_appointment_member_id as member_id','appointment.appointment_classify as classify', 'appointment.appointment_done_json as used_json', 'appointment.appointment_done_datetime as used_time','appointment.join_appointment_member_benefit_id as benefit_id',
  27. 'member.member_mobile','member_cert.member_cert_name'
  28. )
  29. ->when($keywords != '',function($query) use ($keywords){
  30. $query->where('member.member_mobile','like','%'.$keywords.'%');
  31. })->when(!empty($date),function($query) use ($date){
  32. $date[0] = date('Y-m-d',strtotime($date[0])).' 00:00:00';
  33. $date[1] = date('Y-m-d',strtotime($date[1])). ' 23:59:59';
  34. $query->whereBetween('appointment.appointment_done_datetime',$date);
  35. })
  36. ->when($userId != '',function($query) use ($userId){
  37. $query->whereJsonContains('appointment.appointment_done_json->charge->charge_user_id',$userId);
  38. })
  39. ->when($premises != '',function($query) use ($premises){
  40. $query->whereJsonContains('appointment.appointment_done_json->charge->charge_premises',$premises);
  41. })
  42. ->where('appointment_status', 'DONE');
  43. $quotaList = Db::table('member_quota')
  44. ->leftJoin('member','member.member_id' ,'=','member_quota.join_quota_member_id')
  45. ->leftJoin('member_cert','member_cert.join_cert_member_id' ,'=','member_quota.join_quota_member_id')
  46. ->select('member_quota.member_quota_id as quota_id', 'member_quota.join_quota_member_id as member_id','member_quota.member_quota_category as classify', 'member_quota.member_quota_used_json as used_json', "member_quota.member_quota_extend_json->writeOffTime as used_time","member_quota.join_member_rule_added_component_id as benefit_id",
  47. 'member.member_mobile','member_cert.member_cert_name')
  48. ->when($keywords != '',function($query) use ($keywords){
  49. $query->where('member.member_mobile','like','%'.$keywords.'%');
  50. })->when(!empty($date),function($query) use ($date){
  51. $date[0] = date('Y-m-d',strtotime($date[0])).' 00:00:00';
  52. $date[1] = date('Y-m-d',strtotime($date[1])). ' 23:59:59';
  53. $query->whereBetween('member_quota.member_quota_extend_json->writeOffTime',$date);
  54. })
  55. ->when($userId != '',function($query) use ($userId){
  56. $query->whereJsonContains('member_quota.member_quota_used_json->charge->charge_user_id',$userId);
  57. })
  58. ->when($premises != '',function($query) use ($premises){
  59. $query->whereJsonContains('member_quota.member_quota_used_json->charge->charge_premises',$premises);
  60. })
  61. ->where('member_quota_status', 'USED')
  62. ->union($appointmentList);
  63. $total = $quotaList->count('*');
  64. $quotaList = $quotaList->orderBy('used_time', 'DESC')
  65. ->forPage($page, $pageSize)
  66. ->get();
  67. $rows = [];
  68. foreach ($quotaList as $item) {
  69. $username = '';
  70. $premises = '';
  71. $benefitName = '';
  72. if (!empty($item->used_json)) {
  73. $usedJson = json_decode($item->used_json,true);
  74. if (isset($usedJson['charge']) && isset($usedJson['charge']['charge_user_id'])){
  75. $username = SysUser::where('user_id',$usedJson['charge']['charge_user_id'])->value('user_name');
  76. }
  77. if (isset($usedJson['charge']) && isset($usedJson['charge']['charge_premises'])){
  78. $premises = $usedJson['charge']['charge_premises'];
  79. }
  80. if (substr($item->quota_id,0,2) == 'AP'){
  81. $benefitName = MemberBenefit::where('member_benefit_id',$item->benefit_id)->value('member_benefit_name');
  82. }elseif (substr($item->quota_id,0,2) == 'MQ'){
  83. $benefitName = RuleAddedComponent::where('rule_added_component_id',$item->benefit_id)->value('rule_added_component_name');
  84. }
  85. }
  86. $classify = "SERVICE";
  87. if(substr($item->quota_id,0,2) == "MQ"){
  88. $classify = "QUOTA";
  89. }elseif(!empty($item->classify) && $item->classify == 'PACKAGE'){
  90. $classify = "PACKAGE";
  91. }
  92. $rows[] = [
  93. 'quota_id' => $item->quota_id,
  94. 'username' => $username,
  95. 'premises' => $premises,
  96. 'benefit_name' => $benefitName,
  97. 'used_time'=>$item->used_time,
  98. 'member_name' => $item->member_cert_name ? $item->member_cert_name.'-' : '',
  99. 'member_mobile' => $item->member_mobile ? $item->member_mobile : '',
  100. 'classify'=>$classify,
  101. 'nbr'=>1
  102. ];
  103. }
  104. return json_success('', compact('rows', 'page', 'pageSize', 'total'));
  105. }
  106. }