diff --git a/app/api/controller/Course.php b/app/api/controller/Course.php index 6b27362f..f24bdccd 100644 --- a/app/api/controller/Course.php +++ b/app/api/controller/Course.php @@ -88,7 +88,6 @@ class Course extends Controller $params = $this->postForm(); $course = CourseModel::withoutGlobalScope()->where('course_id',$params['course_id'])->find(); - print_r($course); if(empty($course)){ return $this->renderError("没有课程"); } diff --git a/app/api/controller/Retail.php b/app/api/controller/Retail.php index 5503a1da..a0613ede 100644 --- a/app/api/controller/Retail.php +++ b/app/api/controller/Retail.php @@ -15,6 +15,7 @@ use think\response\Json; use app\api\model\Retail as RetailModel; use app\api\model\RetailOrder as RetailOrderModel; use app\api\model\Agreement as AgreementModel; +use app\common\model\RetailDescribe as RetailDescribeModel; use app\api\service\order\Checkout as CheckoutService; class Retail extends Controller @@ -60,7 +61,7 @@ class Retail extends Controller if (!$client['client']) { return $this->renderError('客户端不能为空'); } - $model =new \app\api\model\user\Retail(); + $model =new \app\api\service\Retail(); $list = $model->userCenter($client); return $this->renderSuccess(compact('list')); @@ -88,4 +89,14 @@ class Retail extends Controller } + /** + * 商厂权限 + */ + public function describe() + { + $list = RetailDescribeModel::withoutGlobalScope()->select(); + return $this->renderSuccess(compact('list')); + } + + } \ No newline at end of file diff --git a/app/api/model/Retail.php b/app/api/model/Retail.php index e260138a..613ef99f 100644 --- a/app/api/model/Retail.php +++ b/app/api/model/Retail.php @@ -64,15 +64,15 @@ class Retail extends RetailModel } - public static function detail(array $where = []) - { - $where = [ - 'retail_price_id'=>$where['retail_price_id'], - 'retail_status'=>10 - ]; + // public static function detail(array $where = []) : array + // { + // $where = [ + // 'retail_price_id'=>$where['retail_price_id'], + // 'retail_status'=>10 + // ]; - return RetailModel::where($where)->select(); - } + // return RetailModel::where($where)->select(); + // } diff --git a/app/api/model/user/Retail.php b/app/api/model/user/Retail.php index e0e231fb..547fc337 100644 --- a/app/api/model/user/Retail.php +++ b/app/api/model/user/Retail.php @@ -17,4 +17,6 @@ class Retail extends BaseRetail 'store_id', ]; + + } \ No newline at end of file diff --git a/app/api/model/user/RetailOrder.php b/app/api/model/user/RetailOrder.php index 884d2dc5..671a4141 100644 --- a/app/api/model/user/RetailOrder.php +++ b/app/api/model/user/RetailOrder.php @@ -35,18 +35,30 @@ class RetailOrder extends BaseIdentityOrder * @author: wanghousheng */ public function createOrder(array $identityInfo, $method): bool - { - $price = $identityInfo['retail_current_price'] * $identityInfo['year']; + { + $price = []; + $identityInfo['order_price'] = $identityInfo['retail_current_price'] * $identityInfo['year']; + $preferentialPrice = []; + if($identityInfo['year']>1){ + $price= $identityInfo['retail_current_price'] * $identityInfo['year']-$identityInfo['retail_discounts'];//订单支付价格 + $preferentialPrice = $identityInfo['retail_discounts']; + }else { + $price = $identityInfo['retail_current_price'] * $identityInfo['year']; + $preferentialPrice = 0; + } $data = [ 'user_id' => UserService::getCurrentLoginUserId(),//用户id 'order_no' => OrderService::createOrderNo(),//订单号 'retail_price_id' => $identityInfo['retail_price_id'],//会员id 'order_type' => $identityInfo['retail_type'],//订单类型 + 'order_price' => $identityInfo['order_price'],//订单支付价格 'pay_price' => $price, + 'preferential_price' => $preferentialPrice,//优惠价格 'year' => $identityInfo['year'], 'platform' => getPlatform(), 'pay_method' => $method, 'store_id' => self::$storeId, + ]; return $this->save($data); } diff --git a/app/api/service/Retail/PaySuccess.php b/app/api/service/Retail/PaySuccess.php index 76cd928f..5a14727b 100644 --- a/app/api/service/Retail/PaySuccess.php +++ b/app/api/service/Retail/PaySuccess.php @@ -10,13 +10,13 @@ // +---------------------------------------------------------------------- declare (strict_types=1); -namespace app\api\service\identity; +namespace app\api\service\Retail; use app\api\model\PaymentTrade as PaymentTradeModel; use app\api\model\recharge\Order as OrderModel; use app\api\model\User as UserModel; use app\api\model\user\BalanceLog as BalanceLogModel; -use app\api\model\user\IdentityOrder; +use app\api\model\user\RetailOrder; use app\common\enum\order\PayStatus; use app\common\enum\payment\Method as PaymentMethodEnum; use app\common\enum\recharge\order\PayStatus as PayStatusEnum; @@ -27,6 +27,7 @@ use app\common\library\Lock; use app\common\library\Log; use app\common\service\BaseService; use app\store\model\dealer\User; +use app\common\enum\user\balanceLog\RetailType; use cores\exception\BaseException; /** @@ -37,7 +38,7 @@ use cores\exception\BaseException; class PaySuccess extends BaseService { // 当前订单信息 - public IdentityOrder $orderInfo; + public RetailOrder $orderInfo; // 当前用户信息 private UserModel $userInfo; @@ -58,7 +59,7 @@ class PaySuccess extends BaseService private array $paymentData = []; private int $type; - + /** * 设置支付的订单ID * @param int $orderId 订单ID @@ -72,6 +73,7 @@ class PaySuccess extends BaseService public function setType($type): PaySuccess { $this->type = $type; + return $this; } @@ -119,13 +121,19 @@ class PaySuccess extends BaseService return $this; } + // public function setOrderInfo(array $orderInfo): PaySuccess + // { + // $this->orderInfo = RetailOrder::detail(['order_no' => $this->orderNo]); + // return $this; + // } + /** * 订单支付成功业务处理 * @return bool * @throws BaseException */ public function handle(): bool - { + { // 验证当前参数是否合法 $this->verifyParameters(); // 当前订单开启并发锁 @@ -165,10 +173,10 @@ class PaySuccess extends BaseService /** * 订单模型 - * @return IdentityOrder|null + * @return RetailOrder|null * @throws BaseException */ - private function orderModel(): ?IdentityOrder + private function orderModel(): ?RetailOrder { return $this->getOrderInfo(); } @@ -193,7 +201,7 @@ class PaySuccess extends BaseService // 记录订单支付信息 $this->updatePayInfo(); //更改会员角色 - $this->activate(); + // $this->activate(); }); } @@ -211,7 +219,7 @@ class PaySuccess extends BaseService // 更新用户余额 UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); // 新增余额变动记录 - $type = SceneEnum::MEMBER; + $type = SceneEnum::BUY_SHOP; if ($this->type == IdentityEnum::DEALER) { $type = SceneEnum::DEALER; } @@ -241,7 +249,7 @@ class PaySuccess extends BaseService * @throws BaseException */ private function updateOrderStatus(): void - { + { // 更新订单状态 $this->orderModel()->save([ 'pay_method' => $this->method, @@ -249,6 +257,7 @@ class PaySuccess extends BaseService 'pay_time' => time(), 'trade_id' => $this->tradeId ?: 0, ]); + } /** @@ -318,11 +327,11 @@ class PaySuccess extends BaseService * @return OrderModel|null * @throws BaseException */ - private function getOrderInfo(): ?IdentityOrder - { + private function getOrderInfo(): ?RetailOrder + { // 获取订单详情 (待支付状态) if (empty($this->orderInfo)) { - $this->orderInfo = IdentityOrder::getPayDetail($this->orderNo); + $this->orderInfo = RetailOrder::getPayDetail($this->orderNo); } // 判断订单是否存在 if (empty($this->orderInfo)) { @@ -338,7 +347,7 @@ class PaySuccess extends BaseService private function lockUp() { $orderInfo = $this->getOrderInfo(); - Lock::lockUp("IdentityOrderPaySuccess_{$orderInfo['order_id']}"); + Lock::lockUp("RetailOrderPaySuccess_{$orderInfo['order_id']}"); } /** @@ -348,7 +357,7 @@ class PaySuccess extends BaseService private function unLock() { $orderInfo = $this->getOrderInfo(); - Lock::unLock("IdentityOrderPaySuccess_{$orderInfo['order_id']}"); + Lock::unLock("RetailOrderPaySuccess_{$orderInfo['order_id']}"); } /** diff --git a/app/api/service/Retail/Payment.php b/app/api/service/Retail/Payment.php index 609d68ab..9e9ea07f 100644 --- a/app/api/service/Retail/Payment.php +++ b/app/api/service/Retail/Payment.php @@ -17,7 +17,7 @@ use app\api\model\PaymentTrade as PaymentTradeModel; use app\api\model\Retail as RetailModel; use app\api\model\user\Retail; use app\api\model\user\RetailOrder; -use app\api\service\identity\PaySuccess as RetailPaySuccessService; +use app\api\service\Retail\PaySuccess as RetailPaySuccessService; use app\api\service\Order as OrderService; use app\api\service\User as UserService; use app\common\enum\Client as ClientEnum; @@ -25,6 +25,7 @@ use app\common\enum\OrderType as OrderTypeEnum; use app\common\enum\payment\Method as PaymentMethodEnum; use app\common\enum\user\IdentityEnum; use app\common\library\payment\Facade as PaymentFacade; +use app\common\enum\user\balanceLog\RetailType; use app\common\service\BaseService; use cores\exception\BaseException; use think\db\exception\DataNotFoundException; @@ -115,11 +116,12 @@ class Payment extends BaseService * @author: wanghousheng */ private function orderPayEvent(): void - { + { // 余额支付 if ($this->method == PaymentMethodEnum::BALANCE) { $this->setType($this->orderInfo['order_type'])->orderPaySuccess($this->orderInfo['order_no']); } + } /** diff --git a/app/common/enum/user/balanceLog/RetailType.php b/app/common/enum/user/balanceLog/RetailType.php new file mode 100644 index 00000000..23be70ac --- /dev/null +++ b/app/common/enum/user/balanceLog/RetailType.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\enum\user\balanceLog; + +use app\common\enum\EnumBasics; + +/** + * 余额变动场景枚举类 + * Class Scene + * @package app\common\enum\user\balanceLog + */ +class RetailType extends EnumBasics +{ + // 零售商城 + const RETAIL = 10; + + // 批发商城 + const WHOLESALE = 20; + + /** + * 获取订单类型值 + * @return array + */ + public static function data(): array + { + return [ + self::RETAIL => [ + 'name' => '零售商城', + 'value' => self::RETAIL, + ], + self::WHOLESALE => [ + 'name' => '批发商城', + 'value' => self::WHOLESALE, + ] + ]; + } +} \ No newline at end of file diff --git a/app/common/enum/user/balanceLog/Scene.php b/app/common/enum/user/balanceLog/Scene.php index a0bc8efb..8d6e9dbf 100644 --- a/app/common/enum/user/balanceLog/Scene.php +++ b/app/common/enum/user/balanceLog/Scene.php @@ -32,6 +32,9 @@ class Scene extends EnumBasics // 订单退款 const REFUND = 40; + + //购买商城 + const BUY_SHOP = 50; //开通分销商 const DEALER = 70; @@ -69,6 +72,11 @@ class Scene extends EnumBasics 'value' => self::REFUND, 'describe' => '订单退款:%s', ], + self::BUY_SHOP => [ + 'name' => '购买商城', + 'value' => self::BUY_SHOP, + 'describe' => '购买商城:%s', + ], self::DEALER => [ 'name' => '开通分销商', 'value' => self::DEALER, diff --git a/app/common/model/RetailDescribe.php b/app/common/model/RetailDescribe.php new file mode 100644 index 00000000..da0813b1 --- /dev/null +++ b/app/common/model/RetailDescribe.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; + +use cores\BaseModel; +use think\model\relation\BelongsTo; + +class RetailDescribe extends BaseModel +{ + // 定义表名 + protected $name = 'retail_describe'; + // 定义主键 + protected $pk = 'id'; + + // 开启自动写入时间戳 + protected $autoWriteTimestamp = true; + + // 创建时间字段 + protected $createTime = 'create_time'; + + // 更新时间字段 + protected $updateTime = 'update_time'; + +} \ No newline at end of file diff --git a/app/common/model/RetailOrder.php b/app/common/model/RetailOrder.php index 89275202..387c9dce 100644 --- a/app/common/model/RetailOrder.php +++ b/app/common/model/RetailOrder.php @@ -13,13 +13,14 @@ declare (strict_types=1); namespace app\common\model; use cores\BaseModel; +use think\model\relation\BelongsTo; class RetailOrder extends BaseModel { // 定义表名 protected $name = 'retail_order'; // 定义主键 - protected $pk = 'retail_order_id'; + protected $pk = 'order_id'; // 开启自动写入时间戳 protected $autoWriteTimestamp = true; @@ -30,6 +31,15 @@ class RetailOrder extends BaseModel // 更新时间字段 protected $updateTime = 'update_time'; - + public function user(): BelongsTo + { + $module = self::getCalledModule(); + return $this->belongsTo("app\\{$module}\\model\\User"); + } + + public static function detail($where) + { + return self::get($where); + } } \ No newline at end of file