Browse Source

Merge branch 'master' into custom_manager
代码合并

yb 1 tháng trước cách đây
mục cha
commit
c8e866321d

+ 7 - 3
app/admin/controller/coupon/CouponController.php

@@ -3,6 +3,7 @@
 namespace app\admin\controller\coupon;
 
 use app\admin\service\coupon\CouponDetailService;
+use app\admin\service\coupon\CouponService;
 use app\admin\validate\coupon\CouponValidate;
 use app\admin\validate\device\DeviceValidate;
 use app\controller\Curd;
@@ -108,7 +109,7 @@ class CouponController extends Curd
                         $item['coupon_use_member'] = 'member';
                         $item['memberList'] = $couponJson['member']['list'];
                     } else if (isset($couponJson['member']['where']) && !empty($couponJson['member']['where'])) {
-                        if (trim($couponJson['member']['where']) == '1') {
+                        if (trim($couponJson['member']['where']) == '1' || trim($couponJson['member']['where']) == '') {
                             $item['coupon_use_member'] = 'all';
                         } else {
                             $item['coupon_use_member'] = 'condition';
@@ -124,6 +125,8 @@ class CouponController extends Curd
                                 }
                             }
                         }
+                    }else if(!isset($couponJson['member']['where']) || empty($couponJson['member']['where'])){
+                        $item['coupon_use_member'] = 'all';
                     }
                 }
                 if (isset($couponJson['premises'])) {
@@ -152,6 +155,7 @@ class CouponController extends Curd
                     }
                 }
             }
+            $item['coupon_explain'] = CouponService::couponClassifyInfo($item['coupon_classify'],$item['coupon_category'], $item['coupon_value'], $item['coupon_minimum_limit']);
             unset($item['detail']);
         }
 
@@ -253,7 +257,7 @@ class CouponController extends Curd
     {
         $params = $request->post();
         $data = $this->inputFilter($params);
-        $data['coupon_id'] = "CU" . date("ymdH") . random_string(6, 'up');
+        $data['coupon_id'] = "CU" . date("ymdHi") . random_string(4, 'up');
         if (!empty($params['coupon_use_time']) && $params['coupon_use_time'] == 'date') {
             $data['coupon_validdate_day'] = 0;
             $data['coupon_validdate_begin'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_begin']));
@@ -756,7 +760,7 @@ class CouponController extends Curd
     {
         for ($i = 0; $i < intval($nbr); $i++) {
             CouponDetail::insert([
-                'coupon_detail_id' => 'CUDT' . date("ymdH") . random_string(6, 'up'),
+                'coupon_detail_id' => 'CUDT' . date("ymdHi") . random_string(4, 'up'),
                 'join_detail_coupon_id' => $couponId,
                 'coupon_detail_status' => $couponStatus == 'ACTIVED' ? 'PENDING' : 'INIT',
                 'coupon_detail_addtimes' => time()

+ 3 - 1
app/admin/controller/coupon/CouponPacketController.php

@@ -200,7 +200,7 @@ class CouponPacketController extends Curd
     {
         $params = $request->post();
         $data = $this->inputFilter($params);
-        $data['coupon_packet_id'] = "CP" . date("ymdH") . random_string(6, 'up');
+        $data['coupon_packet_id'] = "CP" . date("ymdHi") . random_string(4, 'up');
         $coupons = [];
         if (!empty($params['coupons'])) {
             foreach ($params['coupons'] as $coupon) {
@@ -379,6 +379,7 @@ class CouponPacketController extends Curd
         } catch (\Exception $e) {
             Db::rollBack();
 
+            dump($e->getMessage());
             return json_fail("发行失败");
         }
     }
@@ -417,6 +418,7 @@ class CouponPacketController extends Curd
                 CouponPacketSequence::insert($insertData);
             }
         } catch (\Exception $e) {
+            dump($e->getMessage());
             throw new BusinessException("发行失败");
         }
     }

+ 33 - 8
app/admin/controller/coupon/CouponPacketSequenceController.php

@@ -170,24 +170,49 @@ class CouponPacketSequenceController extends Curd
             }
         ])->where('coupon_packet_sequence_id', $packetSequenceId)
             ->first();
-        if(!empty($sequence->packet)){
-            if ($sequence->packet->join_coupon_packet_dept_id == 0){
+        if (!empty($sequence->packet)) {
+            if ($sequence->packet->join_coupon_packet_dept_id == 0) {
                 $sequence->packet->dept_name = '所有门店';
-            }else{
+            } else {
                 $sequence->packet->dept_nam = '';
-                $dept = SysDept::where('dept_id',$sequence->packet->join_coupon_packet_dept_id)->select('dept_id','dept_name')->first();
-                if (!empty($dept)){
+                $dept = SysDept::where('dept_id', $sequence->packet->join_coupon_packet_dept_id)->select('dept_id', 'dept_name')->first();
+                if (!empty($dept)) {
                     $sequence->packet->dept_name = $dept->dept_name;
                 }
             }
-            if (!empty($sequence->packet->join_coupon_packet_category_id)){
-                $category = SysCategory::where('category_id',$sequence->packet->join_coupon_packet_category_id)
+            if (!empty($sequence->packet->join_coupon_packet_category_id)) {
+                $category = SysCategory::where('category_id', $sequence->packet->join_coupon_packet_category_id)
                     ->first();
-                if (!empty($category->category_name)){
+                if (!empty($category->category_name)) {
                     $sequence->packet->category_name = $category->category_name;
                 }
             }
         }
+        $coupons = [];
+        if (!empty($sequence->coupon_packet_sequence_json)) {
+            $sequenceJson = json_decode($sequence->coupon_packet_sequence_json, true);
+            if (isset($sequenceJson['coupons'])) {
+                $couponIds = array_keys($sequenceJson['coupons']);
+                $couponModel = Coupon::whereIn('coupon_id', $couponIds)
+                    ->select('coupon_id', 'coupon_name', 'coupon_classify', 'coupon_value', 'coupon_minimum_limit', 'coupon_category')
+                    ->get()
+                    ->toArray();
+                foreach ($couponModel as $coupon) {
+                    foreach ($sequenceJson['coupons'] as $key => $jsonCoupon) {
+                        if ($coupon['coupon_id'] == $key) {
+                            $coupons[] = [
+                                'id' => $key,
+                                'name' => $coupon['coupon_name'],
+                                'nbr' => $jsonCoupon['num'],
+                                'classify' => $coupon['coupon_classify'],
+                                'info' => CouponService::couponClassifyInfo($coupon['coupon_classify'], $coupon['coupon_category'], $coupon['coupon_value'], $coupon['coupon_minimum_limit'])
+                            ];
+                        }
+                    }
+                }
+            }
+        }
+        $sequence->coupons = $coupons;
 
         return json_success('', $sequence);
     }

+ 1 - 1
app/admin/controller/customer/IndexController.php

@@ -164,7 +164,7 @@ class IndexController extends Curd
         Db::beginTransaction();
 
         try {
-            $memberId = "ME" . date("ymdH") . random_string(6, 'up');
+            $memberId = "ME" . date("ymdHi") . random_string(4, 'up');
             $member = [
                 'member_id' => $memberId,
                 'member_is_owner' => 'N',

+ 1 - 1
app/admin/controller/member/BenefitController.php

@@ -150,7 +150,7 @@ class BenefitController extends Curd
                 'write_off_member_id' => $request->post('write_off_member_id'),
                 'join_order_member_id' => $memberId
             ];
-            $writeOffData = OrderService::generateWriteOffData($params);
+            $writeOffData = OrderService::generateWriteOffDataByOrderProcess($params);
 
             $appointments = Appointment::where('join_appointment_member_benefit_id', $benefitId)
                 ->where('appointment_status', 'INIT')

+ 2 - 2
app/admin/controller/member/QuotaController.php

@@ -311,7 +311,7 @@ class QuotaController extends Curd
             } else {
                 $quota = $quotas[0];
                 for ($i = 0; $i < $nbr; $i++) {
-                    $quota['member_quota_id'] = 'MQ' . date('ymdH') . random_string(6, 'up');
+                    $quota['member_quota_id'] = 'MQ' . date('ymdHi') . random_string(4, 'up');
                     $quota['member_quota_status'] = 'USED';
                     $quota['member_quota_used_json'] = json_encode($writeOffData);
                     $quota['member_quota_addtimes'] = strtotime($quota['member_quota_addtimes']);
@@ -406,7 +406,7 @@ class QuotaController extends Curd
                 } else {
                     $quota = $quotas[0];
                     for ($i = 0; $i < $nbr; $i++) {
-                        $quota['member_quota_id'] = 'MQ' . date('ymdH') . random_string(6, 'up');
+                        $quota['member_quota_id'] = 'MQ' . date('ymdHi') . random_string(4, 'up');
                         $quota['member_quota_status'] = 'USED';
                         $quota['member_quota_used_json'] = json_encode($writeOffData);
                         $quota['member_quota_addtimes'] = strtotime($quota['member_quota_addtimes']);

+ 1 - 1
app/admin/controller/member/RoleController.php

@@ -93,7 +93,7 @@ class RoleController extends Curd
     protected function insertInput(Request $request): array
     {
         $data = $this->inputFilter($request->post());
-        $data['member_role_id'] = "MR" . date('ymdH') . random_string(6, 'up');
+        $data['member_role_id'] = "MR" . date('ymdHi') . random_string(4, 'up');
 
         $data['member_role_rule_json'] = json_encode([
             'pricing' => $request->post('join_member_role_rule_pricing_id',''),

+ 1 - 1
app/admin/controller/member/RuleAddedController.php

@@ -97,7 +97,7 @@ class RuleAddedController extends Curd
     protected function insertInput(Request $request): array
     {
         $data = $this->inputFilter($request->post());
-        $data['rule_added_id'] = "RA" . date("ymdH") . random_string(6, 'up');
+        $data['rule_added_id'] = "RA" . date("ymdHi") . random_string(4, 'up');
 
         return $data;
     }

+ 1 - 1
app/admin/controller/member/RulePricingController.php

@@ -54,7 +54,7 @@ class RulePricingController extends Curd
     protected function insertInput(Request $request): array
     {
         $data = $this->inputFilter($request->post());
-        $data['rule_pricing_id'] = "RP" . date("ymdH") . random_string(6, 'up');
+        $data['rule_pricing_id'] = "RP" . date("ymdHi") . random_string(4, 'up');
         $data['rulr_priceing_nbr'] = $data['rulr_priceing_nbr'] / 100;
 //        if (!empty($data['rule_pricing_goods_json'])) {
 //            $data['rule_pricing_goods_json'] = json_encode(explode(',', $data['rule_pricing_goods_json']));

+ 4 - 4
app/admin/controller/order/KangyangCityController.php

@@ -234,7 +234,7 @@ class KangyangCityController extends Curd
                 if (Member::where('member_mobile', $params['mobile'])->exists()) {
                     throw new BusinessException('会员已存在');
                 }
-                $params['join_order_member_id'] = $params['member_id'] = 'MR' . date('ymdH') . random_string(6, 'up');
+                $params['join_order_member_id'] = $params['member_id'] = 'MR' . date('ymdHi') . random_string(4, 'up');
                 // 创建会员
                 MemberService::createMember($params);
             } else if (empty($params['join_order_member_id']) && empty($params['mobile'])) {
@@ -245,8 +245,8 @@ class KangyangCityController extends Curd
             }
 
             $qrcodePayAmount = 0;
-            $params['orderId'] = 'OD' . date('ymdH') . random_string(6, 'up');
-            $params['orderGroupId'] = 'OD' . date('ymdH') . random_string(6, 'up');
+            $params['orderId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
+            $params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
             // 查询是否有未完全支付订单
             $paidOrder = Order::where('join_order_member_id', $params['join_order_member_id'])
                 ->where('order_category', 'VIP')
@@ -423,7 +423,7 @@ class KangyangCityController extends Curd
 
         $params['orderId'] = $params['order_id'];
 
-        $params['orderGroupId'] = 'OD' . date('ymdH') . random_string(6, 'up');
+        $params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
         $order->order_groupby = $params['orderGroupId'];
 
         $goods = Goods::where('goods_id', $params['join_sheet_goods_id'])

+ 2 - 2
app/admin/controller/order/PayDetailController.php

@@ -336,8 +336,8 @@ class PayDetailController extends Curd
                 $data['pay_amount'] = $goods->goods_sales_price;
             }
 
-            $orderId = "OD" . date('ymdH') . random_string(6, 'up');
-            $orderGroupId = "OD" . date('ymdH') . random_string(6, 'up');
+            $orderId = "OD" . date('ymdHi') . random_string(4, 'up');
+            $orderGroupId = "OD" . date('ymdHi') . random_string(4, 'up');
             $orderData = [
                 'order_id' => $orderId,
                 'order_groupby' => $orderGroupId,

+ 2 - 2
app/admin/controller/order/ReturnController.php

@@ -106,10 +106,10 @@ class ReturnController extends Curd
         try {
             [$id, $data] = $this->updateInput($request);
 
-            if($data['order_return_status'] == 'DOING'){
+//            if($data['order_return_status'] == 'DOING'){
                 $data['order_return_accept_datetime'] = date('Y-m-d H:i:s');
                 $data['join_order_return_user_id'] = JwtToken::getCurrentId();
-            }
+//            }
 
             $this->doUpdate($id, $data);
 

+ 98 - 30
app/admin/controller/order/WholeController.php

@@ -408,7 +408,7 @@ class WholeController extends Curd
                 } else {
                     $item['skus'] = [];
                 }
-                if (in_array($item['goods']['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE']) && $order->order_status_system == 'DONE') {
+                if (in_array($item['goods']['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
                     $item['appontment'] = [];
                     $appontments = Appointment::where('join_appointment_order_id', $orderId)
                         ->where('appointment_status', 'DONE')
@@ -544,7 +544,7 @@ class WholeController extends Curd
                         $classify = CouponService::couponClassifyInfo($coupon->coupon_classify, $coupon->coupon_category, $coupon->coupon_value, $coupon->coupon_minimum_limit);
                         $discount['coupon_name'] .= $coupon->coupon_classify . ':' . $coupon->coupon_name . '(优惠¥' . sprintf("%.2f", $discountItem['coupon_value']) . '), ';
                     }
-                    if ($discountItem['coupon_classify'] == '退款'){
+                    if ($discountItem['coupon_classify'] == '退款') {
                         continue;
                     }
                     if (empty($discountItem['coupon_id']) && !empty($discountItem['coupon_classify'])) {
@@ -885,7 +885,7 @@ class WholeController extends Curd
                     $order->order_status_system = $systemStatus;
                     $order->order_status_payment = 'SUCCESS';
                 }
-            }  else if ($params['pay_category'] == 'VIP') {    // 余额支付
+            } else if ($params['pay_category'] == 'VIP') {    // 余额支付
                 $account = MemberAccount::where('join_account_member_id', $params['join_order_member_id'])
                     ->where('member_account_classify', 'VIP')
                     ->where('member_account_status', 'ACTIVED')
@@ -1148,7 +1148,7 @@ class WholeController extends Curd
                 $payData['pay_prepayid'] = $params['join_order_member_id'] . '-CASH';
             } else if ($params['pay_category'] == 'WELFARE') {
                 $payData['pay_prepayid'] = $params['join_order_member_id'] . '-WELFARE';
-            }  else if ($params['pay_category'] == 'VIP') {
+            } else if ($params['pay_category'] == 'VIP') {
                 $payData['pay_prepayid'] = $params['join_order_member_id'] . '-VIP';
             } else if ($params['pay_category'] == 'CARD') {
                 $payData['pay_prepayid'] = $params['card_nbr'];
@@ -1213,11 +1213,11 @@ class WholeController extends Curd
                 foreach ($params['goodsContentList'] as $goods) {
                     $params['join_sheet_goods_id'] = $goods['goods_id'];
                     if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
-                        $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                        $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                         $params['order_sheet_num'] = $goods['nbr'];
                         // 预约表
                         for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                            $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                            $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                             // 入预约记录
                             $this->insertAppointment($params, $writeOffDate, $applyData);
                         }
@@ -1237,10 +1237,10 @@ class WholeController extends Curd
                         foreach ($components as $component) {
                             $componentJson = json_decode($component['goods_component_json'], true);
                             $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
-                            $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                            $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                             $params['order_sheet_num'] = $goods['nbr'] * $componentJson['nbr'];
                             for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                                $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                                $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                                 // 入预约记录
                                 $this->insertAppointment($params, $writeOffDate);
                             }
@@ -1658,11 +1658,11 @@ class WholeController extends Curd
                 foreach ($params['goodsContentList'] as $goods) {
                     $params['join_sheet_goods_id'] = $goods['goods_id'];
                     if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
-                        $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                        $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                         $params['order_sheet_num'] = $goods['nbr'];
                         // 预约表
                         for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                            $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                            $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                             // 入预约记录
                             $this->insertAppointment($params, $writeOffDate, $applyData);
                         }
@@ -1682,10 +1682,10 @@ class WholeController extends Curd
                         foreach ($components as $component) {
                             $componentJson = json_decode($component['goods_component_json'], true);
                             $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
-                            $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                            $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                             $params['order_sheet_num'] = $goods['nbr'] * $componentJson['nbr'];
                             for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                                $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                                $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                                 // 入预约记录
                                 $this->insertAppointment($params, $writeOffDate);
                             }
@@ -1946,7 +1946,7 @@ class WholeController extends Curd
                 }
             }
             // 余额、福利、储值卡 验证短信
-            if ($params['settlement_now'] == 'Y' && $params['pay_constitute'] == 'N' && in_array($params['pay_category'], ['CASH', 'CARD', 'WELFARE','VIP'])) {
+            if ($params['settlement_now'] == 'Y' && $params['pay_constitute'] == 'N' && in_array($params['pay_category'], ['CASH', 'CARD', 'WELFARE', 'VIP'])) {
                 $code = $params['sms_code'];
                 if (!$code) {
                     throw new BusinessException('验证码错误,请重新输入');
@@ -1972,7 +1972,7 @@ class WholeController extends Curd
                 if (Member::where('member_mobile', $params['mobile'])->exists()) {
                     throw new BusinessException('会员已存在');
                 }
-                $params['join_order_member_id'] = $params['member_id'] = 'MR' . date('ymdH') . random_string(6, 'up');
+                $params['join_order_member_id'] = $params['member_id'] = 'MR' . date('ymdHi') . random_string(4, 'up');
                 // 创建会员
                 MemberService::createMember($params);
             } else if (empty($params['join_order_member_id']) && empty($params['mobile'])) {
@@ -1983,8 +1983,8 @@ class WholeController extends Curd
             }
 
             $qrcodePayAmount = 0;
-            $params['orderId'] = 'OD' . date('ymdH') . random_string(6, 'up');
-            $params['orderGroupId'] = 'OD' . date('ymdH') . random_string(6, 'up');
+            $params['orderId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
+            $params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
 
             $systemStatus = 'SENDING';  // 待发货
             // 立即结算
@@ -2366,13 +2366,13 @@ class WholeController extends Curd
                 foreach ($params['goodsContentList'] as $goods) {
                     $params['join_sheet_goods_id'] = $goods['goods_id'];
                     if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
-                        $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                        $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                         $params['join_sheet_goods_sku_id'] = $goods['sku_id'];
                         $params['goods_id'] = $goods['goods_id'];
                         $params['order_sheet_num'] = $goods['nbr'];
                         // 预约表
                         for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                            $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                            $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                             // 入预约记录
                             $this->insertAppointment($params, $writeOffDate, $applyData);
                         }
@@ -2392,10 +2392,10 @@ class WholeController extends Curd
                         foreach ($components as $component) {
                             $componentJson = json_decode($component['goods_component_json'], true);
                             $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
-                            $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                            $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                             $params['order_sheet_num'] = $goods['nbr'] * $componentJson['nbr'];
                             for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                                $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                                $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                                 // 入预约记录
                                 $this->insertAppointment($params, $writeOffDate);
                             }
@@ -2577,7 +2577,7 @@ class WholeController extends Curd
                 if (Member::where('member_mobile', $params['mobile'])->exists()) {
                     throw new BusinessException("会员已存在");
                 }
-                $params['join_order_member_id'] = $params['member_id'] = 'MR' . date('ymdH') . random_string(6, 'up');
+                $params['join_order_member_id'] = $params['member_id'] = 'MR' . date('ymdHi') . random_string(4, 'up');
                 // 创建会员
                 MemberService::createMember($params);
             } else if (empty($params['join_order_member_id']) && empty($params['mobile'])) {
@@ -2588,9 +2588,9 @@ class WholeController extends Curd
             }
 
             $qrcodePayAmount = 0;
-            $params['orderId'] = 'OD' . date('ymdH') . random_string(6, 'up');
-            $params['orderGroupId'] = 'OD' . date('ymdH') . random_string(6, 'up');
-            $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+            $params['orderId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
+            $params['orderGroupId'] = 'OD' . date('ymdHi') . random_string(4, 'up');
+            $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
 
             $systemStatus = 'SENDING';  // 待发货
             // 立即结算
@@ -2850,13 +2850,13 @@ class WholeController extends Curd
                 foreach ($params['goodsContentList'] as $goods) {
                     $params['join_sheet_goods_id'] = $goods['goods_id'];
                     if (isset($goods['goods_classify']) && in_array($goods['goods_classify'], ['SERVICE', 'CHNMED', 'CHNNCD'])) {
-                        $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                        $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                         $params['join_sheet_goods_sku_id'] = $goods['sku_id'];
                         $params['goods_id'] = $goods['goods_id'];
                         $params['order_sheet_num'] = $goods['nbr'];
                         // 预约表
                         for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                            $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                            $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                             // 入预约记录
                             $this->insertAppointment($params, $writeOffDate, $applyData);
                         }
@@ -2876,10 +2876,10 @@ class WholeController extends Curd
                         foreach ($components as $component) {
                             $componentJson = json_decode($component['goods_component_json'], true);
                             $params['join_sheet_goods_sku_id'] = $componentJson['sku_id'];
-                            $params['benefitId'] = 'BF' . date('ymdH') . random_string(6, 'up');
+                            $params['benefitId'] = 'BF' . date('ymdHi') . random_string(4, 'up');
                             $params['order_sheet_num'] = $goods['nbr'] * $componentJson['nbr'];
                             for ($i = 0; $i < intval($params['order_sheet_num']); $i++) {
-                                $params['appointmentId'] = 'AP' . date('ymdH') . random_string(6, 'up');
+                                $params['appointmentId'] = 'AP' . date('ymdHi') . random_string(4, 'up');
                                 // 入预约记录
                                 $this->insertAppointment($params, $writeOffDate);
                             }
@@ -4395,10 +4395,13 @@ class WholeController extends Curd
                 $payDetail0 = $payDetails[0];
                 $payTimes = $payDetail0['pay_paytimes'];
             }
-            if ($item['member']['member_mobile'] == '0000') {
+            if (!empty($item['member']) && $item['member']['member_mobile'] == '0000') {
                 $memberName = '散客';
             } else {
-                $memberName = (!empty($item['cert']) ? $item['cert']['member_cert_name'] : substr($item['member']['member_mobile'], -4) . '用户') . '-' . $item['member']['member_mobile'];
+                $memberName = !empty($item['cert']) ? $item['cert']['member_cert_name'] : (!empty($item['member']) ? (substr($item['member']['member_mobile'], -4) . '用户' . '-') : '');
+                if (!empty($item['member'])) {
+                    $memberName .= $item['member']['member_mobile'];
+                }
             }
             $data[$key] = [
                 'goods_classify' => !empty($goodsClassify) && isset(self::$goodsClassify[$goodsClassify]) ? self::$goodsClassify[$goodsClassify] : '其他订单',
@@ -4610,6 +4613,71 @@ class WholeController extends Curd
         return json_success("success", ['pay_amount' => $amountBalance['pay_amount']]);
     }
 
+
+    /**
+     * @Desc 订单的核销记录
+     * @Author Gorden
+     * @Date 2024/9/13 14:28
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function writeOffList(Request $request)
+    {
+        $orderId = $request->get('order_id');
+        $page = $request->get('page', 1);
+        $pageSize = $request->get('pageSize', 20);
+        if (!$orderId) {
+            return json_fail("参数异常");
+        }
+
+        $appointments = Appointment::with([
+            'member' => function ($query) {
+                $query->select('member_id', 'member_mobile');
+            },
+            'memberInfo',
+            'cert',
+            'goods' => function ($query) {
+                $query->select('goods_id', 'goods_name');
+            }
+        ])->where('join_appointment_order_id', $orderId)
+            ->where('appointment_status', 'DONE')
+            ->select('join_appointment_member_id', 'join_appointment_goods_id', 'appointment_done_datetime', 'appointment_done_json');
+        $total = $appointments->count();
+        $rows = $appointments->forPage($page, $pageSize)
+            ->orderBy('appointment_done_datetime', 'DESC')
+            ->get();
+        foreach ($rows as &$item) {
+            $memberMobile = '';
+            if (!empty($item['member']) && !empty($item['member']['member_mobile'])) {
+                $memberMobile = $item['member']['member_mobile'];
+            }
+            $memberNickname = '';
+            if (!empty($item['member_info']) && !empty($item['member_info']['member_info_nickname'])) {
+                $memberNickname = $item['member_info']['member_info_nickname'];
+            }
+            $memberName = '';
+            if (!empty($item['cert']) && !empty($item['cert']['member_cert_name'])) {
+                $memberName = $item['cert']['member_cert_name'];
+            }
+            unset($item['member'], $item['member_info'], $item['cert']);
+            $item['member_name'] = MemberService::getMemberName($memberMobile, $memberName, $memberNickname);
+            if (!empty($item['appointment_done_json'])) {
+                $doneJson = json_decode($item['appointment_done_json'], true);
+                if (isset($doneJson['charge']) && !empty($doneJson['charge']['charge_user_id'])) {
+                    $item['username'] = SysUser::where('user_id', $doneJson['charge']['charge_user_id'])->value('user_name');
+                }
+                if (isset($doneJson['charge']) && !empty($doneJson['charge']['charge_premises'])) {
+                    $item['premise'] = $doneJson['charge']['charge_premises'];
+                }
+                $item['nbr'] = 1;
+            }
+        }
+
+
+        return json_success('', compact('rows', 'page', 'pageSize', 'total'));
+    }
+
     public static $goodsClassify = [
         // goodsClassify: {GOODS:"健康产品订单",SERVICE:"服务订单",DEVICE:"设备订单",SPECIAL:"专题业务订单",PACKAGE:"套餐订单",RECHARGE:"充值订单",OTHER:"其他订单"},
 

+ 1 - 1
app/admin/controller/sys_manage/ApiController.php

@@ -31,7 +31,7 @@ class ApiController extends Curd
     protected function insertInput(Request $request): array
     {
         $data = $this->inputFilter($request->post());
-        $data['api_id'] = "AP" . date('ymdH') . random_string(6, 'up');
+        $data['api_id'] = "AP" . date('ymdHi') . random_string(4, 'up');
         $data['api_extend_json'] = $data['api_extend_json'] ?? '{}';
         $data['api_request_json'] = $data['api_request_json'] ?? '{}';
         $data['api_response_json'] = $data['api_response_json'] ?? '{}';

+ 1 - 1
app/admin/service/coupon/CouponDetailService.php

@@ -21,7 +21,7 @@ class CouponDetailService
     {
         try {
             CouponDetail::insert([
-                'coupon_detail_id' => 'CUDT' . date("ymdH") . random_string(6, 'up'),
+                'coupon_detail_id' => 'CUDT' . date("ymdHi") . random_string(4, 'up'),
                 'join_detail_coupon_id' => $params['coupon_id'],
                 'join_coupon_detail_member_id' => $params['member_id'],
                 'coupon_detail_status' => 'ACTIVED',

+ 3 - 3
app/admin/service/goods/GoodsService.php

@@ -1107,7 +1107,7 @@ class GoodsService
     {
         Db::beginTransaction();
         try {
-            $params['goods_id'] = "GD" . date('ymdH') . random_string(6, 'up');
+            $params['goods_id'] = "GD" . date('ymdHi') . random_string(4, 'up');
             // 主表
             self::mainInsert($params);
             // 商品详情表
@@ -1155,7 +1155,7 @@ class GoodsService
         try {
             Db::beginTransaction();
             $goods = new Goods();
-            $goods->goods_id = "GD" . date('ymdH') . random_string(6, 'up');
+            $goods->goods_id = "GD" . date('ymdHi') . random_string(4, 'up');
             $goods->join_goods_category_id = 59;
             $goods->goods_classify = 'RECHARGE';
             $goods->goods_status = $params['goods_status'];
@@ -1231,7 +1231,7 @@ class GoodsService
     {
         Db::beginTransaction();
         try {
-            $params['goods_id'] = "GD" . date('ymdH') . random_string(6, 'up');
+            $params['goods_id'] = "GD" . date('ymdHi') . random_string(4, 'up');
             // 主表
             self::mainInsert($params);
             // 商品详情表

+ 11 - 4
app/admin/service/member/MemberService.php

@@ -108,6 +108,9 @@ class MemberService
                 'member_info_birthday' => !empty($row['member_info_birthday']) ? $row['member_info_birthday'] : '',
                 'member_info_gender' => !empty($row['member_info_gender']) ? $row['member_info_gender'] : '',
             ];
+            if (substr($row['info']['member_info_headimg'],0,2) == '..'){
+                $row['info']['member_info_headimg'] = '';
+            }
             if (!empty($row['info']['member_info_address']) && in_array($row['info']['member_info_address'], ['请选择', '省-市-区'])) {
                 $row['info']['member_info_address'] = '';
             }
@@ -943,7 +946,7 @@ class MemberService
             $memberId = $params['member_id'];
             $member = Member::where('member_id', $params['member_id'])->first();
             if (!$member) {
-                return json_fail("暂无数据");
+                throw new BusinessException('数据异常');
             }
             $extendJson = [];
             if (!empty($member->member_extend_json)) {
@@ -954,7 +957,7 @@ class MemberService
             if (!empty($params['user_id'])) {
                 $deptId = SysUser::where('user_id', $params['user_id'])->value('join_user_dept_id');
                 if (!$deptId) {
-                    throw new BusinessException('请先关联业务员和门店');
+                    throw new BusinessException('您选择的业务员没有关联门店');
                 }
                 $extendJson['belong'] = ['user_id' => $params['user_id'], 'premises' => $deptId];
             }
@@ -1029,7 +1032,11 @@ class MemberService
             }
 
             Db::commit();
-        } catch (\Exception $e) {
+        }catch (BusinessException $e){
+            Db::rollBack();
+            dump($e->getMessage() . ';line:' . $e->getLine());
+            return json_fail($e->getMessage());
+        }catch (\Exception $e) {
             Db::rollBack();
             dump($e->getMessage() . ';line:' . $e->getLine());
             return json_fail("数据更新失败");
@@ -1236,7 +1243,7 @@ class MemberService
     {
         $id = SysSerial::getSerial();
 
-        return "MR" . date('ymdH') . random_string(6, 'up');
+        return "MR" . date('ymdHi') . random_string(4, 'up');
     }
 
     public static function getMemberName($mobile, $certName, $nickname)

+ 1 - 1
app/admin/service/notify/RechargeService.php

@@ -246,7 +246,7 @@ class RechargeService
     private static function doSaveMemberQuota($memberId, $component, $nbr)
     {
         $model = new MemberQuota();
-        $model->member_quota_id = 'MQ' . date('ymdH') . random_string(6, 'up');
+        $model->member_quota_id = 'MQ' . date('ymdHi') . random_string(4, 'up');
         $model->join_quota_member_id = $memberId;
         $model->join_member_rule_added_component_id = $component['rule_added_component_id'];
         $model->member_quota_status = 'PENDING';

+ 124 - 123
app/admin/service/order/AppointmentService.php

@@ -35,7 +35,7 @@ class AppointmentService
         $status = $request->get('status', '');
         $premisesName = $request->get('premises', '');
         $appointmentMode = $request->get('appointment_mode', '');
-        $type = $request->get('type','');
+        $type = $request->get('type', '');
 
         $rows = Db::table('appointment')
             ->leftJoin('member', 'member.member_id', '=', 'appointment.join_appointment_member_id')
@@ -46,30 +46,31 @@ class AppointmentService
             ->leftJoin('order_return', 'order_return.join_return_order_id', '=', 'appointment.join_appointment_order_id')
             ->leftJoin('member_benefit', 'member_benefit.member_benefit_id', '=', 'appointment.join_appointment_member_benefit_id')
             ->leftJoin('goods_sku', 'goods_sku.goods_sku_id', '=', 'appointment.join_appointment_goods_sku_id')
-            ->whereIn('appointment_status',['PAYING','WAITING','PENDING','DOING','DONE','CANCEL','REVOKE'])
+            ->whereIn('appointment_status', ['PAYING', 'WAITING', 'PENDING', 'DOING', 'DONE', 'CANCEL', 'REVOKE'])
             ->when($id != '', function ($query) use ($id) {
                 $query->where('appointment.appointment_id', 'like', '%' . $id . '%');
             })->when($mobile != '', function ($query) use ($mobile) {
-                $query->where(function($query2) use ($mobile) {
+                $query->where(function ($query2) use ($mobile) {
                     $query2->where('member.member_mobile', 'like', '%' . $mobile . '%')
-                    ->orWhere('member_cert.member_cert_name', 'like', '%' . $mobile . '%');
+                        ->orWhere('member_cert.member_cert_name', 'like', '%' . $mobile . '%');
                 });
             })->when($status != '', function ($query) use ($status) {
                 $query->where('appointment.appointment_status', $status);
-            })->when($premisesName != '',function($query) use ($premisesName){
-                $query->whereJsonContains('appointment_apply_json->premises',$premisesName);
-            })->when($appointmentMode != '',function($query) use ($appointmentMode){
-                if($appointmentMode == 'ONLINE'){
-                    $query->whereIn('appointment_mode',['ONLINE','ORDER']);
-                }else{
-                    $query->where('appointment_mode',$appointmentMode);
+            })->when($premisesName != '', function ($query) use ($premisesName) {
+                $query->whereJsonContains('appointment_apply_json->premises', $premisesName);
+            })->when($appointmentMode != '', function ($query) use ($appointmentMode) {
+                if ($appointmentMode == 'ONLINE') {
+                    $query->whereIn('appointment_mode', ['ONLINE', 'ORDER']);
+                } else {
+                    $query->where('appointment_mode', $appointmentMode);
                 }
-            })->when(!empty($type), function ($query) use ($type){
-                if ($type == 'todayDONE'){
-                    $query->where('appointment_status','DONE');
-                    $query->whereBetween('appointment_addtimes',[strtotime(date('Y-m-d').' 00:00:00'),strtotime(date('Y-m-d').' 23:59:59')]);
-                }elseif ($type == 'todayAppointment'){
-                    $query->where('appointment_datetime',date('Y-m-d'));
+            })->when(!empty($type), function ($query) use ($type) {
+                if ($type == 'todayDONE') {
+                    $query->where('appointment_status', 'DONE');
+                    $query->whereRaw('LEFT(appointment_done_datetime,10)=?', [date('Y-m-d')]);
+//                    $query->whereBetween('appointment_addtimes',[strtotime(date('Y-m-d').' 00:00:00'),strtotime(date('Y-m-d').' 23:59:59')]);
+                } elseif ($type == 'todayAppointment') {
+                    $query->where('appointment_datetime', date('Y-m-d'));
                 }
             });
 
@@ -79,10 +80,10 @@ class AppointmentService
             'member_cert.member_cert_name',
             'member_info.member_info_nickname',
             'goods.goods_name', 'goods.goods_cover', 'goods.goods_sales_price',
-            'order.order_id','order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay',
-            'order.order_category', 'order.order_status_system', 'order.order_status_payment', 'order.order_status_storage','order.order_is_complete',
-            'order.order_addtimes','order_return.order_return_status',
-            'member_benefit.member_benefit_name','member_benefit.member_benefit_id as benefit_id'
+            'order.order_id', 'order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay',
+            'order.order_category', 'order.order_status_system', 'order.order_status_payment', 'order.order_status_storage', 'order.order_is_complete',
+            'order.order_addtimes', 'order_return.order_return_status',
+            'member_benefit.member_benefit_name', 'member_benefit.member_benefit_id as benefit_id'
         )
             ->orderBy('appointment.appointment_addtimes', 'desc')
             ->forPage($page, $pageSize)
@@ -93,12 +94,12 @@ class AppointmentService
             $row->goods_sku_specs_json = !empty($row->goods_sku_specs_json) ? json_decode($row->goods_sku_specs_json, true) : [];
             $row->order_addtimes = date('Y-m-d H:i:s', $row->order_addtimes);
             $row->appointment_addtimes = date('Y-m-d H:i:s', $row->appointment_addtimes);
-            $row->appointment_apply_json = !empty($row->appointment_apply_json) ? json_decode($row->appointment_apply_json,true) : [];
-            $row->appointment_doing_json = !empty($row->appointment_doing_json) ? json_decode($row->appointment_doing_json,true) : [];
-            $row->appointment_result_json = !empty($row->appointment_result_json) ? json_decode($row->appointment_result_json,true) : [];
+            $row->appointment_apply_json = !empty($row->appointment_apply_json) ? json_decode($row->appointment_apply_json, true) : [];
+            $row->appointment_doing_json = !empty($row->appointment_doing_json) ? json_decode($row->appointment_doing_json, true) : [];
+            $row->appointment_result_json = !empty($row->appointment_result_json) ? json_decode($row->appointment_result_json, true) : [];
             if ($row->appointment_category == 'NOFEE') {
                 $row->member_benefit_name = "后付费预约";
-            }elseif ($row->appointment_category == 'GREENWAY'){
+            } elseif ($row->appointment_category == 'GREENWAY') {
                 $row->member_benefit_name = "就医绿通";
             }
             if (!empty($row->appointment_apply_json)) {
@@ -107,12 +108,12 @@ class AppointmentService
                 $row->appointment_times = $applyJson['times'] ?? '';
             }
 
-            $skus = GoodsSku::where('join_sku_goods_id',$row->join_appointment_goods_id)->where('goods_sku_status','ON')
-                ->where('goods_sku_id',$row->join_appointment_goods_sku_id)
-                ->select('goods_sku_id','goods_sku_specs_json','goods_sku_sales_price')
+            $skus = GoodsSku::where('join_sku_goods_id', $row->join_appointment_goods_id)->where('goods_sku_status', 'ON')
+                ->where('goods_sku_id', $row->join_appointment_goods_sku_id)
+                ->select('goods_sku_id', 'goods_sku_specs_json', 'goods_sku_sales_price')
                 ->get();
             $skuJson = [];
-            foreach ($skus as $key => $sku){
+            foreach ($skus as $key => $sku) {
                 if (!empty($sku->goods_sku_specs_json)) {
                     $specsJson = json_decode($sku->goods_sku_specs_json, true);
                     $skuTitle = '';
@@ -158,22 +159,22 @@ class AppointmentService
      */
     public static function arrival(Request $request)
     {
-        $appointmentId = $request->post('id','');
-        if (!$appointmentId){
+        $appointmentId = $request->post('id', '');
+        if (!$appointmentId) {
             return json_fail("参数异常");
         }
 
-        $appointment = Appointment::where('appointment_id',$appointmentId)->first();
-        
+        $appointment = Appointment::where('appointment_id', $appointmentId)->first();
+
         Db::beginTransaction();
-        try{
+        try {
             $appointment->appointment_doing_datetime = date('Y-m-d H:i:s');
             $appointment->appointment_status = 'DOING';
             $appointment->save();
             Db::commit();
 
             return json_success('操作成功');
-        }catch(\Exception $e){
+        } catch (\Exception $e) {
             dump($e->getMessage());
             Db::rollBack();
             return json_fail('到店状态修改失败');
@@ -186,31 +187,31 @@ class AppointmentService
      */
     public static function done(Request $request)
     {
-        $appointmentId = $request->post('id','');
-        $isGenerateOrder = $request->post('is_generate_order','');
-        if (!$appointmentId || !$isGenerateOrder){
+        $appointmentId = $request->post('id', '');
+        $isGenerateOrder = $request->post('is_generate_order', '');
+        if (!$appointmentId || !$isGenerateOrder) {
             return json_fail("参数异常");
         }
 
-        $appointment = Appointment::where('appointment_id',$appointmentId)->first();
-        
-        
+        $appointment = Appointment::where('appointment_id', $appointmentId)->first();
+
+
         Db::beginTransaction();
-        try{
+        try {
             $appointment->appointment_done_datetime = date('Y-m-d H:i:s');
             $appointment->appointment_status = 'DONE';
             // 不产生订单,走核销
-            if ($isGenerateOrder == 'N'){
+            if ($isGenerateOrder == 'N') {
                 $appointment->save();
 
                 Db::commit();
                 return json_success('操作成功');
             }
-            $applyJson = json_decode($appointment->appointment_apply_json,true);
-            $goods = Goods::where('goods_id',$appointment->join_appointment_goods_id)->first();
-            $sku = GoodsSku::where('goods_sku_id',$appointment->join_appointment_goods_sku_id)->where('goods_sku_status','ON')->first();
-            $orderId = 'OD' . date('ymdH') . random_string(6, 'up');
-            $groupBy = 'OD' . date('ymdH') . random_string(6, 'up');
+            $applyJson = json_decode($appointment->appointment_apply_json, true);
+            $goods = Goods::where('goods_id', $appointment->join_appointment_goods_id)->first();
+            $sku = GoodsSku::where('goods_sku_id', $appointment->join_appointment_goods_sku_id)->where('goods_sku_status', 'ON')->first();
+            $orderId = 'OD' . date('ymdHi') . random_string(4, 'up');
+            $groupBy = 'OD' . date('ymdHi') . random_string(4, 'up');
             $order = [
                 'order_id' => $orderId,
                 'order_groupby' => $groupBy,
@@ -225,7 +226,7 @@ class AppointmentService
                 'order_status_storage' => 'PENDING',
                 'order_platform' => 'SYSTEM',
                 'order_addtimes' => time(),
-                'order_config_json' => json_encode(['premises'=>$applyJson['premises']])
+                'order_config_json' => json_encode(['premises' => $applyJson['premises']])
             ];
             Order::insert($order);
             // 订单号更新到预约
@@ -252,14 +253,14 @@ class AppointmentService
             $pay = [
                 'join_pay_member_id' => $appointment->join_appointment_member_id,
                 'join_pay_order_id' => $groupBy,
-                'pay_status'=>'WAITING',
+                'pay_status' => 'WAITING',
                 'pay_amount' => $sheet['order_sheet_pay'],
                 'pay_remark' => '预约单',
                 'pay_addtimes' => time(),
                 'pay_paytimes' => date('Y-m-d H:i:s'),
-                'pay_prepayid'=>$appointment->join_appointment_member_id.'-CASH',
-                'pay_category'=>$goods->goods_classify,
-                'join_pay_object_json' => ['order_id'=>$orderId]
+                'pay_prepayid' => $appointment->join_appointment_member_id . '-CASH',
+                'pay_category' => $goods->goods_classify,
+                'join_pay_object_json' => ['order_id' => $orderId]
             ];
             PayDetail::insert($pay);
 
@@ -267,7 +268,7 @@ class AppointmentService
             Db::commit();
 
             return json_success('操作成功');
-        }catch(\Exception $e){
+        } catch (\Exception $e) {
             dump($e->getMessage());
             Db::rollBack();
             return json_fail('到店状态修改失败');
@@ -289,16 +290,16 @@ class AppointmentService
         try {
             // 如果没有,新建
             if (empty($params['join_appointment_member_id']) && !empty($params['username']) && !empty($params['mobile'])) {
-                if(Member::where('member_mobile',$params['mobile'])->exists()){
+                if (Member::where('member_mobile', $params['mobile'])->exists()) {
                     Db::rollBack();
                     return json_fail('会员已存在,请勿重复创建');
                 }
-                $memberId = 'MR' . date('ymdH') . random_string(6, 'up');
+                $memberId = 'MR' . date('ymdHi') . random_string(4, 'up');
                 $params['join_appointment_member_id'] = $params['member_id'] = $memberId;
                 // 创建会员
                 MemberService::createMember($params);
             }
-            $appointmentId = "AP" . date('ymdH') . random_string(6, 'up');
+            $appointmentId = "AP" . date('ymdHi') . random_string(4, 'up');
             $data = [
                 'appointment_id' => $appointmentId,
                 'join_appointment_member_id' => $params['join_appointment_member_id'] ?? '',
@@ -331,7 +332,7 @@ class AppointmentService
                     'mobile' => $member['member_mobile'],
                     'person' => $params['person'],
                     'remark' => '',
-                    'remark_apply_employe' => $params['remark_apply_employe'] ?? '',  
+                    'remark_apply_employe' => $params['remark_apply_employe'] ?? '',
                     'premises' => $params['premises'],
                     'times' => $params['appointment_times']
                 ]);
@@ -339,17 +340,17 @@ class AppointmentService
 
             Appointment::insert($data);
             Db::commit();
-            _syslog("预约","添加预约成功");
+            _syslog("预约", "添加预约成功");
             return json_success("添加预约成功");
-        }catch (BusinessException $e){
+        } catch (BusinessException $e) {
             Db::rollBack();
 
-            _syslog("预约","添加预约失败");
+            _syslog("预约", "添加预约失败");
             return json_fail($e->getMessage());
         } catch (\Exception $e) {
             Db::rollBack();
             dump($e->getMessage());
-            _syslog("预约","添加预约失败");
+            _syslog("预约", "添加预约失败");
             return json_fail("添加预约失败");
         }
     }
@@ -421,13 +422,13 @@ class AppointmentService
                     }
                 ])->where('member_id', $params['join_appointment_member_id'])
                     ->first();
-                if(!$member){
+                if (!$member) {
                     throw new BusinessException("核销人员不存在");
                 }
                 $member = $member->toArray();
                 $applyJson = [];
-                if (!empty($appointment->appointment_apply_json)){
-                    $applyJson = json_decode($appointment->appointment_apply_json,true);
+                if (!empty($appointment->appointment_apply_json)) {
+                    $applyJson = json_decode($appointment->appointment_apply_json, true);
                 }
                 $applyJson['name'] = !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'];
                 $applyJson['mobile'] = $member['member_mobile'];
@@ -452,9 +453,9 @@ class AppointmentService
 
             // 如果服务结束,没有生成过订单,生成订单
             if ($params['appointment_status'] == 'DONE' && empty($appointment->join_appointment_order_id) && $params['settlement_mode'] != 'QUOTA') {
-                $sku = GoodsSku::find($params['join_appointment_goods_sku_id']);    
-                $orderId = 'OD' . date('ymdH') . random_string(6, 'up');
-                $groupBy = 'OD' . date('ymdH') . random_string(6, 'up');
+                $sku = GoodsSku::find($params['join_appointment_goods_sku_id']);
+                $orderId = 'OD' . date('ymdHi') . random_string(4, 'up');
+                $groupBy = 'OD' . date('ymdHi') . random_string(4, 'up');
                 $order = [
                     'order_id' => $orderId,
                     'order_groupby' => $groupBy,
@@ -497,9 +498,9 @@ class AppointmentService
                     'pay_amount' => $sheet['order_sheet_pay'],
                     'pay_remark' => '预约单',
                     'pay_addtimes' => time(),
-                    'pay_prepayid' => $params['join_appointment_member_id'].'-'.$params['settlement_mode'],
+                    'pay_prepayid' => $params['join_appointment_member_id'] . '-' . $params['settlement_mode'],
                     'pay_paytimes' => date('Y-m-d H:i:s'),
-                    'pay_category'=>$goods->goods_classify
+                    'pay_category' => $goods->goods_classify
                 ];
                 // 现金余额结算
                 if ($params['settlement_mode'] == 'CASH') {
@@ -514,10 +515,10 @@ class AppointmentService
                     if ($amount < $sheet['order_sheet_pay']) {
                         throw new BusinessException("账户余额不足");
                     } else {
-                        if($account->member_account_surplus < $sheet['order_sheet_pay']){
-                            $account->member_account_added = $account->member_account_added - ($sheet['order_sheet_pay']-$account->member_account_surplus);
+                        if ($account->member_account_surplus < $sheet['order_sheet_pay']) {
+                            $account->member_account_added = $account->member_account_added - ($sheet['order_sheet_pay'] - $account->member_account_surplus);
                             $account->member_account_surplus = 0;
-                        }else{
+                        } else {
                             $account->member_account_surplus = $account->member_account_surplus - $sheet['order_sheet_pay'];
                         }
                         MemberAccount::where('member_account_id', $account->member_account_id)->update([
@@ -529,7 +530,7 @@ class AppointmentService
                         $pay['join_pay_object_json'] = json_encode(['payment' => ['member_account_id' => $account->member_account_id]]);
                         // 更新订单状态
 
-                        Order::where('order_id', $orderId)->update(['order_status_system' => 'DONE','order_is_complete'=>'Y', 'order_status_payment' => 'SUCCESS']);
+                        Order::where('order_id', $orderId)->update(['order_status_system' => 'DONE', 'order_is_complete' => 'Y', 'order_status_payment' => 'SUCCESS']);
                         OrderSheet::where('join_sheet_order_id', $orderId)->update(['order_sheet_status' => 'DONE']);
                     }
                     // $pay['pay_category'] = 'CASH';
@@ -552,7 +553,7 @@ class AppointmentService
                         $pay['pay_status'] = 'SUCCESS';
                         $pay['join_pay_object_json'] = json_encode(['payment' => ['member_account_id' => $account->member_account_id]]);
                         // 更新订单状态
-                        Order::where('order_id', $orderId)->update(['order_status_system' => 'DONE','order_is_complete'=>'Y', 'order_status_payment' => 'SUCCESS']);
+                        Order::where('order_id', $orderId)->update(['order_status_system' => 'DONE', 'order_is_complete' => 'Y', 'order_status_payment' => 'SUCCESS']);
                         OrderSheet::where('join_sheet_order_id', $orderId)->update(['order_sheet_status' => 'DONE']);
                     }
                     // $pay['pay_category'] = 'CASH';
@@ -562,31 +563,31 @@ class AppointmentService
                     $pay['pay_status'] = 'SUCCESS';
                     PayDetail::insert($pay);
                     // 更新订单状态
-                    Order::where('order_id', $orderId)->update(['order_status_system' => 'DONE','order_is_complete'=>'Y', 'order_status_payment' => 'SUCCESS']);
+                    Order::where('order_id', $orderId)->update(['order_status_system' => 'DONE', 'order_is_complete' => 'Y', 'order_status_payment' => 'SUCCESS']);
                     OrderSheet::where('join_sheet_order_id', $orderId)->update(['order_sheet_status' => 'DONE']);
                 }
 
                 // 回写权益表
-                $benefitId = 'BF'.date('ymdH').random_string(6,'up');
+                $benefitId = 'BF' . date('ymdHi') . random_string(4, 'up');
                 $benefitData = [
-                    'member_benefit_id'=>$benefitId,
-                    'join_benefit_member_id'=>$params['join_appointment_member_id'],
-                    'join_benefit_goods_id'=>$params['join_appointment_goods_id'],
-                    'join_benefit_goods_sku_id'=>$params['join_appointment_goods_sku_id'] ?? '',
-                    'join_benefit_order_id'=>$orderId,
-                    'member_benefit_status'=>'DONE',
-                    'member_benefit_name'=>$goods->goods_name,
-                    'member_benefit_limit_count'=>1,
-                    'member_benefit_used_count'=>1,
-                    'member_benefit_addtimes'=>time()
+                    'member_benefit_id' => $benefitId,
+                    'join_benefit_member_id' => $params['join_appointment_member_id'],
+                    'join_benefit_goods_id' => $params['join_appointment_goods_id'],
+                    'join_benefit_goods_sku_id' => $params['join_appointment_goods_sku_id'] ?? '',
+                    'join_benefit_order_id' => $orderId,
+                    'member_benefit_status' => 'DONE',
+                    'member_benefit_name' => $goods->goods_name,
+                    'member_benefit_limit_count' => 1,
+                    'member_benefit_used_count' => 1,
+                    'member_benefit_addtimes' => time()
                 ];
                 MemberBenefit::insert($benefitData);
-                
+
                 // $premisesName = SysDept::where('dept_id',$params['premises'])->value('dept_name');
                 // 记录核销
                 $paramsData = [
                     'dept_premises_id' => $params['premises'],
-                    'order_remark'=>$params['appointment_remark'],
+                    'order_remark' => $params['appointment_remark'],
                     'write_off_member_id' => $params['write_off_member_id'],
                     'join_order_member_id' => $params['join_appointment_member_id'],
                 ];
@@ -600,55 +601,55 @@ class AppointmentService
                 ]);
             }
             // 已有服务核销
-            if($params['appointment_status'] == 'DONE' && $params['settlement_mode'] == 'QUOTA' && !empty($params['quota_id'])){
+            if ($params['appointment_status'] == 'DONE' && $params['settlement_mode'] == 'QUOTA' && !empty($params['quota_id'])) {
                 // $premisesName = SysDept::where('dept_id',$params['premises'])->value('dept_name');
                 $paramsData = [
-                    'member_id'=>$params['join_appointment_member_id'],
-                    'nbr'=>$params['person'],
-                    'times'=>date('Y-m-d H:i:s'),
+                    'member_id' => $params['join_appointment_member_id'],
+                    'nbr' => $params['person'],
+                    'times' => date('Y-m-d H:i:s'),
                     'write_off_member_id' => $params['write_off_member_id'],
-                    'remark'=>$params['appointment_remark'],
-                    'dept_premises_id'=>$params['premises']
+                    'remark' => $params['appointment_remark'],
+                    'dept_premises_id' => $params['premises']
                 ];
-                $quotaType = substr($params['quota_id'],0,2);
-                if($quotaType == 'MQ'){
-                    $quota = MemberQuota::where('member_quota_id',$params['quota_id'])
-                    ->select('member_quota_id','join_member_rule_added_component_id')
-                    ->first()
-                    ->toArray();
+                $quotaType = substr($params['quota_id'], 0, 2);
+                if ($quotaType == 'MQ') {
+                    $quota = MemberQuota::where('member_quota_id', $params['quota_id'])
+                        ->select('member_quota_id', 'join_member_rule_added_component_id')
+                        ->first()
+                        ->toArray();
                     $paramsData['component_id'] = $quota['join_member_rule_added_component_id'];
 
                     QuotaController::doWriteOff($paramsData);
                     // 回写权益ID
-                    if(empty($appointment->join_appointment_member_benefit_id)){
+                    if (empty($appointment->join_appointment_member_benefit_id)) {
                         Appointment::where('appointment_id', $appointmentId)->update(['join_appointment_member_benefit_id' => $params['quota_id']]);
                     }
-                }else if($quotaType == 'BF'){
+                } else if ($quotaType == 'BF') {
                     $paramsData['benefit_id'] = $params['quota_id'];
-                    BenefitController::doWriteOff($paramsData,$appointment);
+                    BenefitController::doWriteOff($paramsData, $appointment);
 
                     // 清除后付费预约
-                    if($appointment->appointment_category == 'NOFEE'){
+                    if ($appointment->appointment_category == 'NOFEE') {
                         Appointment::where('appointment_id', $appointmentId)->delete();
                     }
                 }
 
-                _syslog("预约","已有服务核销");
+                _syslog("预约", "已有服务核销");
             }
 
 
             Db::commit();
-            _syslog("预约","预约数据更新成功");
+            _syslog("预约", "预约数据更新成功");
             return json_success("数据更新成功");
-        }catch(\support\exception\BusinessException $e){
+        } catch (\support\exception\BusinessException $e) {
             Db::rollBack();
-            dump($e->getFile().'--'.$e->getLine());
-            _syslog("预约","预约数据更新失败");
+            dump($e->getFile() . '--' . $e->getLine());
+            _syslog("预约", "预约数据更新失败");
             return json_fail($e->getMessage());
         } catch (\Exception $e) {
             Db::rollBack();
-            dump($e->getFile().'--'.$e->getLine());
-            _syslog("预约","预约数据更新失败");
+            dump($e->getFile() . '--' . $e->getLine());
+            _syslog("预约", "预约数据更新失败");
             return json_fail("数据更新失败");
         }
     }
@@ -659,26 +660,26 @@ class AppointmentService
     public static function cancelApply(Request $request)
     {
 
-        $appointmentId = $request->post('id','');
-        if (!$appointmentId){
+        $appointmentId = $request->post('id', '');
+        if (!$appointmentId) {
             return json_fail("参数异常");
         }
 
-        $appointment = Appointment::where('appointment_id',$appointmentId)->first();
-        if(!$appointment){
+        $appointment = Appointment::where('appointment_id', $appointmentId)->first();
+        if (!$appointment) {
             return json_fail("参数异常");
         }
 
-        try{
+        try {
             $appointment->appointment_status = 'CANCEL';
             $appointment->appointment_cancel_datetime = date('Y-m-d H:i:s');
             $appointment->save();
 
             return json_success('取消成功');
-        }catch(\Exception $e){
+        } catch (\Exception $e) {
             return json_fail('取消失败');
         }
-        
+
     }
 
     public static function getTimes(Request $request)
@@ -687,12 +688,12 @@ class AppointmentService
         $date = $request->get('date', '');
 //        $memberId = $request->get('member_id', '');
         $appointmentId = $request->get('appointment_id', '');
-        $premisesName = $request->get('premisses','');
+        $premisesName = $request->get('premisses', '');
         if (!$goodsId || !$date) {
             return json_fail("查询时间段失败!");
         }
 
-        if (!$premisesName){
+        if (!$premisesName) {
             return json_fail("请先选择预约场所");
         }
 
@@ -704,7 +705,7 @@ class AppointmentService
         // 当前服务已预约出去的
         $appointments = Appointment::where('join_appointment_goods_id', $goodsId)
             ->where('appointment_datetime', $date)
-            ->whereJsonContains('appointment_apply_json->premises',$premisesName)
+            ->whereJsonContains('appointment_apply_json->premises', $premisesName)
             ->when($appointmentId != '', function ($query) use ($appointmentId) {
                 $query->where('appointment_id', '<>', $appointmentId);
             })
@@ -723,7 +724,7 @@ class AppointmentService
                     if (!empty($appointment['appointment_apply_json'])) {
                         $applyJson = json_decode($appointment['appointment_apply_json'], true);
                         $applyJsonTimes = $applyJson['times'] ?? '';
-                        
+
                         if ($time['duration'] == $applyJsonTimes) {
                             $times[$key]['person'] -= $applyJson['person'];
                             if ($times[$key]['person'] < 1) {

+ 2 - 2
app/admin/service/sys_manage/UserService.php

@@ -278,8 +278,8 @@ class UserService
 
     public static function generateUserId()
     {
-        $random = random_string(6,'up');
+        $random = random_string(4,'up');
 
-        return 'UR' . date('ymdH') . $random;
+        return 'UR' . date('ymdHi') . $random;
     }
 }

+ 1 - 1
app/event/order/KangyangCityEvent.php

@@ -78,7 +78,7 @@ class KangyangCityEvent
                     $num = $coupon['num'];
                     for ($i = 0; $i < $num; $i++) {
                         CouponDetail::insert([
-                            'coupon_detail_id' => 'CUDT' . date("ymdH") . random_string(6, 'up'),
+                            'coupon_detail_id' => 'CUDT' . date("ymdHi") . random_string(4, 'up'),
                             'join_detail_coupon_id' => $key,
                             'join_coupon_detail_member_id' => $params['member_id'],
                             'coupon_detail_status' => 'ACTIVED',

+ 1 - 0
route/admin.php

@@ -935,6 +935,7 @@ Route::group('/admin', function () {
             Route::post('/customPrinter', [\app\admin\controller\order\WholeController::class, 'customPrinter']);
             Route::post('/cancelOrder', [\app\admin\controller\order\WholeController::class, 'cancelOrder']);
             Route::get('/getOrderPayStatus', [\app\admin\controller\order\WholeController::class, 'getOrderPayStatus']);
+            Route::get('/writeOffList', [\app\admin\controller\order\WholeController::class, 'writeOffList']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);