123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace app\admin\controller\member;
- use app\controller\Curd;
- use app\model\Appointment;
- use app\model\MemberBenefit;
- use app\model\MemberQuota;
- use app\model\RuleAddedComponent;
- use app\model\SysUser;
- use support\Db;
- use support\Request;
- class WriteOffController extends Curd
- {
- public function __construct()
- {
- // $this->model = new ;
- }
- public function list(Request $request)
- {
- $page = $request->get('page', 1);
- $pageSize = $request->get('pageSize', 50);
- $keywords = $request->get('keywords', '');
- $userId = $request->get('user_id', '');
- $premises = $request->get('premises', '');
- $date = $request->get('date', []);
- $memberId = $request->get('member_id','');
- $appointmentList = Db::table('appointment')
- ->leftJoin('member', 'member.member_id', '=', 'appointment.join_appointment_member_id')
- ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'appointment.join_appointment_member_id')
- ->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',
- 'member.member_mobile', 'member_cert.member_cert_name','appointment_extend_json as extend_json'
- )
- ->when($keywords != '', function ($query) use ($keywords) {
- $query->where('member.member_mobile', 'like', '%' . $keywords . '%');
- })->when(!empty($date), function ($query) use ($date) {
- $date[0] = date('Y-m-d', strtotime($date[0])) . ' 00:00:00';
- $date[1] = date('Y-m-d', strtotime($date[1])) . ' 23:59:59';
- $query->whereBetween('appointment.appointment_done_datetime', $date);
- })->when($userId != '', function ($query) use ($userId) {
- $query->whereJsonContains('appointment.appointment_done_json->charge->charge_user_id', $userId);
- })->when($premises != '', function ($query) use ($premises) {
- $query->whereJsonContains('appointment.appointment_done_json->charge->charge_premises', $premises);
- })->when(!empty($memberId),function ($query) use ($memberId){
- $query->where('join_appointment_member_id',$memberId);
- })
- ->where('appointment_status', 'DONE');
- $quotaList = Db::table('member_quota')
- ->leftJoin('member', 'member.member_id', '=', 'member_quota.join_quota_member_id')
- ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'member_quota.join_quota_member_id')
- ->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",
- 'member.member_mobile', 'member_cert.member_cert_name','member_quota_extend_json as extend_json')
- ->when($keywords != '', function ($query) use ($keywords) {
- $query->where('member.member_mobile', 'like', '%' . $keywords . '%');
- })->when(!empty($date), function ($query) use ($date) {
- $date[0] = date('Y-m-d', strtotime($date[0])) . ' 00:00:00';
- $date[1] = date('Y-m-d', strtotime($date[1])) . ' 23:59:59';
- $query->whereBetween('member_quota.member_quota_extend_json->writeOffTime', $date);
- })
- ->when($userId != '', function ($query) use ($userId) {
- $query->whereJsonContains('member_quota.member_quota_used_json->charge->charge_user_id', $userId);
- })
- ->when($premises != '', function ($query) use ($premises) {
- $query->whereJsonContains('member_quota.member_quota_used_json->charge->charge_premises', $premises);
- })
- ->where('member_quota_status', 'USED')
- ->union($appointmentList);
- $total = $quotaList->count('*');
- $quotaList = $quotaList->orderBy('used_time', 'DESC')
- ->forPage($page, $pageSize)
- ->get();
- $rows = [];
- foreach ($quotaList as $item) {
- $username = '';
- $premises = '';
- $benefitName = '';
- if (!empty($item->used_json)) {
- $usedJson = json_decode($item->used_json, true);
- if (isset($usedJson['charge']) && isset($usedJson['charge']['charge_user_id'])) {
- $username = SysUser::where('user_id', $usedJson['charge']['charge_user_id'])->value('user_name');
- }
- if (isset($usedJson['charge']) && isset($usedJson['charge']['charge_premises'])) {
- $premises = $usedJson['charge']['charge_premises'];
- }
- if (substr($item->quota_id, 0, 2) == 'AP') {
- $benefitName = MemberBenefit::where('member_benefit_id', $item->benefit_id)->value('member_benefit_name');
- } elseif (substr($item->quota_id, 0, 2) == 'MQ') {
- $benefitName = RuleAddedComponent::where('rule_added_component_id', $item->benefit_id)->value('rule_added_component_name');
- }
- }
- $remark = [];
- if (!empty($item->extend_json)){
- $extendJson = json_decode($item->extend_json,true);
- if (isset($extendJson['remark'])){
- $remark = $extendJson['remark'];
- }
- }
- $classify = "SERVICE";
- if (substr($item->quota_id, 0, 2) == "MQ") {
- $classify = "QUOTA";
- } elseif (!empty($item->classify) && $item->classify == 'PACKAGE') {
- $classify = "PACKAGE";
- }
- $rows[] = [
- 'quota_id' => $item->quota_id,
- 'username' => $username,
- 'premises' => $premises,
- 'benefit_name' => $benefitName,
- 'used_time' => $item->used_time,
- 'member_name' => $item->member_cert_name ? $item->member_cert_name : '',
- 'member_mobile' => $item->member_mobile ? $item->member_mobile : '',
- 'classify' => $classify,
- 'nbr' => 1,
- 'remark'=>$remark
- ];
- }
- return json_success('', compact('rows', 'page', 'pageSize', 'total'));
- }
- /**
- * @Desc 核销备注
- * @Author Gorden
- * @Date 2024/9/4 17:05
- *
- * @param Request $request
- * @return \support\Response
- */
- public function remark(Request $request)
- {
- $quotaId = $request->post('quota_id', '');
- if (!$quotaId) {
- return json_fail('参数异常');
- }
- $extendJson = [];
- if (substr($quotaId, 0, 2) == 'AP') {
- $appointment = Appointment::where('appointment_id', $quotaId)->first();
- if (!empty($appointment->appointment_extend_json)) {
- $extendJson = json_decode($appointment->appointment_extend_json, true);
- }
- } elseif (substr($quotaId, 0, 2) == 'MQ') {
- $quota = MemberQuota::where('member_quota_id', $quotaId)->first();
- if (!empty($quota->member_quota_extend_json)) {
- $extendJson = json_decode($quota->member_quota_extend_json, true);
- }
- }
- if (empty($appointment) && empty($quota)) {
- return json_fail("数据异常");
- }
- try {
- $extendJson['remark'] = [
- 'premises_id' => $request->post('premises_id', ''),
- 'premises_name' => $request->post('premises_name', ''),
- 'business' => $request->post('business', ''),
- 'service' => $request->post('service', '')
- ];
- if (!empty($appointment)){
- $appointment->appointment_extend_json = json_encode($extendJson,JSON_UNESCAPED_UNICODE);
- $appointment->save();
- }elseif (!empty($quota)){
- $quota->member_quota_extend_json = json_encode($extendJson,JSON_UNESCAPED_UNICODE);
- $quota->save();
- }
- return json_success('success');
- } catch (\Exception $e) {
- return json_fail('备注保存失败');
- }
- }
- }
|