From d1add7930e734e5604055328f34bfefc9e7c319e Mon Sep 17 00:00:00 2001 From: lqmac Date: Fri, 20 Sep 2024 12:16:34 +0800 Subject: [PATCH] =?UTF-8?q?h5=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Cashier.php | 4 ++ app/api/controller/Goods.php | 1 + app/api/controller/Recharge.php | 8 +++ app/api/model/recharge/Order.php | 6 ++- app/api/service/Identity.php | 14 +++++ app/api/service/Retail.php | 7 +++ app/api/service/Setting.php | 7 ++- app/api/service/cashier/Payment.php | 7 +++ app/api/service/recharge/Payment.php | 8 +-- app/command/SyncGoodsToPerMinute.php | 2 + app/common/model/Payment.php | 23 ++++++-- app/common/model/h5/Setting.php | 4 +- app/store/controller/user/Recharge.php | 39 ++++++++++++++ app/store/model/recharge/Order.php | 74 +++++++++++++++++++++++++- 14 files changed, 192 insertions(+), 12 deletions(-) diff --git a/app/api/controller/Cashier.php b/app/api/controller/Cashier.php index 488ef050..dda4cdf6 100644 --- a/app/api/controller/Cashier.php +++ b/app/api/controller/Cashier.php @@ -34,6 +34,10 @@ class Cashier extends Controller */ public function orderInfo(int $orderId, string $client): Json { + //微信端特殊处理一下 + if ($client == 'WXOFFICIAL') { + $client = 'H5'; + } $CashierService = new CashierService; $data = $CashierService->setOrderId($orderId)->setClient($client)->orderInfo(); return $this->renderSuccess($data); diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 23d8c387..1b2cf4a2 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -85,6 +85,7 @@ class Goods extends Controller //获取客服设置 $service = new SettingService; $setting = $service->getGoodsCustomer($merchantId,$storeId); + $goodsInfo['setting'] = $setting; return $this->renderSuccess(['detail' => $goodsInfo]); } diff --git a/app/api/controller/Recharge.php b/app/api/controller/Recharge.php index c8d45ebc..398085cd 100644 --- a/app/api/controller/Recharge.php +++ b/app/api/controller/Recharge.php @@ -33,6 +33,10 @@ class Recharge extends Controller */ public function center(string $client): Json { + //微信端特殊处理一下 + if ($client == 'WXOFFICIAL') { + $client = 'H5'; + } $RechargeService = new RechargeService; $data = $RechargeService->center($client); return $this->renderSuccess($data); @@ -49,6 +53,10 @@ class Recharge extends Controller public function submit(): Json { $data = $this->postForm(); + if ($data['method'] == 'WXOFFICIAL') { + $data['method'] = 'H5'; + } + $RechargeService = new RechargeService; $data = $RechargeService->setMethod($data['method']) ->setClient($data['client']) diff --git a/app/api/model/recharge/Order.php b/app/api/model/recharge/Order.php index 90db430d..7650cf85 100644 --- a/app/api/model/recharge/Order.php +++ b/app/api/model/recharge/Order.php @@ -78,7 +78,7 @@ class Order extends OrderModel * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public function createOrder(?int $planId = null, ?string $customMoney = null) + public function createOrder(?int $planId = null, ?string $customMoney = null, array $extra = []) { // 确定充值方式 $rechargeType = $planId > 0 ? RechargeTypeEnum::PLAN : RechargeTypeEnum::CUSTOM; @@ -89,6 +89,10 @@ class Order extends OrderModel } // 获取订单数据 $data = $this->getOrderData($rechargeType, $planId, $customMoney); + $data['order']['voucher_type'] = $extra['voucherType'] ?? ""; + $data['order']['payer_name'] = $extra['payerName'] ?? ""; + $data['order']['payer_phone'] = $extra['payerPhone'] ?? ""; + $data['order']['upload_images'] = isset($extra['uploadImages']) && $extra['uploadImages'] ? json_encode($extra['uploadImages']) : ""; // 记录订单信息 return $this->saveOrder($data); } diff --git a/app/api/service/Identity.php b/app/api/service/Identity.php index 318530d6..1e2d6443 100644 --- a/app/api/service/Identity.php +++ b/app/api/service/Identity.php @@ -72,6 +72,13 @@ class Identity extends BaseService // 根据指定客户端获取可用的支付方式 $PaymentModel = new PaymentModel; $methods = $PaymentModel->getMethodsByClient($client); + foreach ($methods as $key => $value) { + if ($value['method'] == "voucher") { + unset($methods[$key]); + + } + } + $methods = array_values($methods); // 返回数据 return [ 'personal' => $userInfo, @@ -120,6 +127,13 @@ class Identity extends BaseService // 根据指定客户端获取可用的支付方式 $PaymentModel = new PaymentModel; $methods = $PaymentModel->getMethodsByClient($client); + foreach ($methods as $key => $value) { + if ($value['method'] == "voucher") { + unset($methods[$key]); + + } + } + $methods = array_values($methods); // 返回数据 return [ 'personal' => $userInfo, diff --git a/app/api/service/Retail.php b/app/api/service/Retail.php index f10baaad..ada0f131 100644 --- a/app/api/service/Retail.php +++ b/app/api/service/Retail.php @@ -72,6 +72,13 @@ class Retail extends BaseService // 根据指定客户端获取可用的支付方式 $PaymentModel = new PaymentModel; $methods = $PaymentModel->getMethodsByClient($client['client']); + foreach ($methods as $key => $value) { + if ($value['method'] == "voucher") { + unset($methods[$key]); + + } + } + $methods = array_values($methods); // 返回数据 return [ 'personal' => $userInfo, diff --git a/app/api/service/Setting.php b/app/api/service/Setting.php index 6b588605..f673734a 100644 --- a/app/api/service/Setting.php +++ b/app/api/service/Setting.php @@ -183,6 +183,11 @@ class Setting extends BaseService public function getGoodsCustomer(int $merchantId ,int $storeId): array { $values = SettingModel::getItem(SettingEnum::CUSTOMER , $storeId ,$merchantId); - return helper::pick($values, ['enabled', 'provider', 'config']); + $setting = helper::pick($values, ['enabled', 'provider', 'config']); + if (isset($setting['config']['ewmkf']['qrCodeId']) && $setting['config']['ewmkf']['qrCodeId']) { + $info = UploadFile::detail($setting['config']['ewmkf']['qrCodeId']); + $setting['config']['ewmkf']['qrCode'] = $info['preview_url'] ?? ""; + } + return $setting; } } \ No newline at end of file diff --git a/app/api/service/cashier/Payment.php b/app/api/service/cashier/Payment.php index ddec3b7e..04b4b57e 100644 --- a/app/api/service/cashier/Payment.php +++ b/app/api/service/cashier/Payment.php @@ -104,6 +104,13 @@ class Payment extends BaseService $merchantId = ($model && $model->channel_id > 0) ? 0 : $orderInfo['merchant_id']; $methods = $PaymentModel->getMethodsByClient($this->client, true, $orderInfo['store_id'], $merchantId); + foreach ($methods as $key => $value) { + if ($value['method'] == "voucher") { + unset($methods[$key]); + + } + } + $methods = array_values($methods); return [ 'order' => $orderInfo, 'personal' => $userInfo, diff --git a/app/api/service/recharge/Payment.php b/app/api/service/recharge/Payment.php index 6eeb0658..2e7ef1e8 100644 --- a/app/api/service/recharge/Payment.php +++ b/app/api/service/recharge/Payment.php @@ -80,7 +80,7 @@ class Payment extends BaseService public function orderPay(?int $planId = null, string $customMoney = null, array $extra = []): array { // 创建余额订单信息 - $this->orderInfo = $this->createOrder($planId, $customMoney); + $this->orderInfo = $this->createOrder($planId, $customMoney, $extra); // 构建第三方支付请求的参数 $payment = $this->unifiedorder($extra); // 记录第三方交易信息 @@ -99,10 +99,10 @@ class Payment extends BaseService * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - private function createOrder(?int $planId = null, string $customMoney = null): OrderModel + private function createOrder(?int $planId = null, string $customMoney = null, array $extra = []): OrderModel { $model = new OrderModel; - if (!$model->createOrder($planId, $customMoney)) { + if (!$model->createOrder($planId, $customMoney, $extra)) { throwError($model->getError() ?: '创建充值订单失败'); } $model['order_id'] = (int)$model['order_id']; @@ -151,7 +151,7 @@ class Payment extends BaseService */ private function recordPaymentTrade(array $payment): void { - if ($this->method != PaymentMethodEnum::BALANCE) { + if (!in_array($this->method, [PaymentMethodEnum::BALANCE, PaymentMethodEnum::VOUCHER])) { PaymentTradeModel::record( $this->orderInfo, $this->method, diff --git a/app/command/SyncGoodsToPerMinute.php b/app/command/SyncGoodsToPerMinute.php index 028f3e97..527f6308 100644 --- a/app/command/SyncGoodsToPerMinute.php +++ b/app/command/SyncGoodsToPerMinute.php @@ -38,6 +38,8 @@ class SyncGoodsToPerMinute extends Command $sql = "SELECT * FROM `yoshop_goods` WHERE goods_id > " . $goods_id . " AND goods_id % ". $div . " = ". $mod ." AND update_time > ".$min_time." order by update_time asc LIMIT ".$limit; $list = Db::query($sql); if (!$list) { + sleep(mt_rand(5,10)); + echo date("Y-m-d H:i:s").PHP_EOL; return true; } $obj = new GoodsCateEs(); diff --git a/app/common/model/Payment.php b/app/common/model/Payment.php index e236d472..73c51de2 100644 --- a/app/common/model/Payment.php +++ b/app/common/model/Payment.php @@ -88,12 +88,12 @@ class Payment extends BaseModel if (empty($merchantId)) { $merchantId = 0; } - //if (!$data = Cache::get("payment_{$storeId}_{$merchantId}")) { - if (true) { + if (!$data = Cache::get("payment_{$storeId}_{$merchantId}")) { + //if (true) { // 获取所有支付方式 $data = $model->dataByStorage($storeId, $defaultData, $merchantId); // 写入缓存中 - //Cache::tag('cache')->set("payment_{$storeId}_{$merchantId}", $data); + Cache::tag('cache')->set("payment_{$storeId}_{$merchantId}", $data); } // 重组缓存数据 (多维) return static::reorganize2($defaultData, $data); @@ -303,7 +303,22 @@ class Payment extends BaseModel $methods = []; foreach ($group['methods'] as $method) { if ($method['method'] == PaymentMethodEnum::VOUCHER) { - $method['template'] = $this->getTemplateInfo($method['template_id']); + + $detail = $this->getTemplateInfo($method['template_id']); + + if (isset($detail['config']['voucher']['alipayQrCodeId']) && $detail['config']['voucher']['alipayQrCodeId']) { + $info = UploadFile::detail($detail['config']['voucher']['alipayQrCodeId']); + $detail['config']['voucher']['alipayQrcode'] = $info['preview_url'] ?? ""; + } + if (isset($detail['config']['voucher']['quickpayQrCodeId']) && $detail['config']['voucher']['quickpayQrCodeId']) { + $info = UploadFile::detail($detail['config']['voucher']['quickpayQrCodeId']); + $detail['config']['voucher']['quickpayQrCode'] = $info['preview_url'] ?? ""; + } + if (isset($detail['config']['voucher']['wechatQrCodeId']) && $detail['config']['voucher']['wechatQrCodeId']) { + $info = UploadFile::detail($detail['config']['voucher']['wechatQrCodeId']); + $detail['config']['voucher']['wechatQrCode'] = $info['preview_url'] ?? ""; + } + $method['template'] = $detail; } if ($method['is_enable'] && ($balance || $method['method'] !== PaymentMethodEnum::BALANCE)) { $methods[] = $method; diff --git a/app/common/model/h5/Setting.php b/app/common/model/h5/Setting.php index 891adffc..061bddaa 100644 --- a/app/common/model/h5/Setting.php +++ b/app/common/model/h5/Setting.php @@ -60,6 +60,7 @@ class Setting extends BaseModel public static function getItem(string $key, ?int $storeId = null): array { $data = static::getAll($storeId); + return isset($data[$key]) ? $data[$key]['values'] : []; } @@ -128,6 +129,7 @@ class Setting extends BaseModel */ public function defaultData(): array { + $model = new static; return [ 'basic' => [ 'key' => 'basic', @@ -136,7 +138,7 @@ class Setting extends BaseModel // 是否启用H5端访问 'enabled' => true, // h5站点url [默认是当前访问的域名] - 'baseUrl' => base_url(), + 'baseUrl' => base_url()."mobile/#/?storeId=".$model::$storeId, ] ] ]; diff --git a/app/store/controller/user/Recharge.php b/app/store/controller/user/Recharge.php index 47732bf0..c54e004b 100644 --- a/app/store/controller/user/Recharge.php +++ b/app/store/controller/user/Recharge.php @@ -33,4 +33,43 @@ class Recharge extends Controller $list = $model->getList($this->request->param()); return $this->renderSuccess(compact('list')); } + + /** + * 充值订单详情 + * @param int $rechargeOrderId + * @return Json + */ + public function detail(int $rechargeOrderId): Json + { + // 售后单详情 + $model = new OrderModel; + $detail = $model->getDetail($rechargeOrderId); + if (!$detail) { + return $this->renderError('未找到该充值记录'); + } + $detail->refuse_desc = $detail->refuse_desc ? htmlspecialchars_decode($detail->refuse_desc) : ""; + return $this->renderSuccess(compact('detail')); + } + + /** + * 商家审核充值 + * @param int $rechargeOrderId + * @return Json + */ + public function audit(int $rechargeOrderId): Json + { + // 售后单详情 + $model = OrderModel::detail($rechargeOrderId); + if ($model->isEmpty()) { + return $this->renderError('未找到该充值记录'); + } + if ($model->audit_status > 0) { + return $this->renderError('已审核'); + } + // 确认审核 + if ($model->audit($rechargeOrderId, $this->postForm())) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError($model->getError() ?: '操作失败'); + } } diff --git a/app/store/model/recharge/Order.php b/app/store/model/recharge/Order.php index 860b9ae7..0490c807 100644 --- a/app/store/model/recharge/Order.php +++ b/app/store/model/recharge/Order.php @@ -13,7 +13,13 @@ declare (strict_types=1); namespace app\store\model\recharge; use app\common\model\recharge\Order as OrderModel; - +use app\common\enum\order\refund\AuditStatus as AuditStatusEnum; +use app\common\enum\payment\Method as PaymentMethodEnum; +use app\common\enum\recharge\order\PayStatus as PayStatusEnum; +use app\api\model\User as UserModel; +use app\common\enum\user\balanceLog\Scene as SceneEnum; +use app\api\model\user\BalanceLog as BalanceLogModel; +use app\common\model\UploadFile; /** * 用户充值订单模型 * Class Order @@ -74,4 +80,70 @@ class Order extends OrderModel } return $filter; } + + + /** + * 获取售后单详情 + * @param int $rechargeOrderId + * @return OrderRefund|false|null + */ + public function getDetail(int $rechargeOrderId) + { + $detail = static::detail($rechargeOrderId, [ + 'user','orderPlan', + ]) ?: false; + if (!$detail) { + return $detail; + } + if ($detail->upload_images) { + $img_ids = json_decode($detail->upload_images, true); + $files = UploadFile::getFileList($img_ids); + + $detail->upload_images = !$files->isEmpty() ? $files->toArray() : []; + } + + return $detail; + } + + /** + * 商家审核 + * @param array $data + * @return bool + */ + public function audit(int $rechargeOrderId, array $data): bool + { + if ($data['audit_status'] == AuditStatusEnum::REJECTED && empty($data['refuse_desc'])) { + $this->error = '请输入拒绝原因'; + return false; + } + + $this->transaction(function () use ($data, $rechargeOrderId) { + if ($data['audit_status'] == AuditStatusEnum::REJECTED) { + $data['pay_status'] = PayStatusEnum::PENDING; + } elseif ($data['audit_status'] == AuditStatusEnum::REVIEWED) { + $data['pay_status'] = PayStatusEnum::SUCCESS; + $data['pay_method'] = PaymentMethodEnum::VOUCHER; + $data['pay_time'] = time(); + } + // var_dump($data); + // exit(); + // 更新售后单状态 + $this->save($data); + // 同意售后申请, 记录退货地址 + if ($data['audit_status'] == AuditStatusEnum::REVIEWED) { + $orderInfo = self::detail($rechargeOrderId); + //新增用户充值记录和给用户加余额 + // 累积用户余额 + UserModel::setIncBalance((int)$orderInfo['user_id'], (float)$orderInfo['actual_money']); + // 用户余额变动明细 + BalanceLogModel::add(SceneEnum::RECHARGE, [ + 'user_id' => $orderInfo['user_id'], + 'money' => $orderInfo['actual_money'], + 'store_id' => empty($orderInfo['store_id'])?$this->getStoreId():$orderInfo['store_id'], + ], ['order_no' => $orderInfo['order_no']],$orderInfo['store_id']); + } + + }); + return true; + } }