下单未完成

lszyh
haoyuntao 5 months ago
parent 0c560aa199
commit 28f2056660
  1. 135
      app/api/controller/Retail.php
  2. 10
      app/api/model/Retail.php
  3. 20
      app/api/model/RetailOrder.php
  4. 35
      app/common/model/RetailOrder.php
  5. 1
      app/store/controller/Retail.php
  6. 3
      app/store/model/Retail.php

@ -13,7 +13,9 @@ namespace app\api\controller;
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\api\service\order\Checkout as CheckoutService;
class Retail extends Controller
{
@ -25,7 +27,7 @@ class Retail extends Controller
*/
public function list(int $retailType): Json
{
$list = RetailModel::withoutGlobalScope()->where('retail_type',$retailType)->select();
$list = RetailModel::withoutGlobalScope()->where('retail_type',$retailType)->where('retail_status',10)->select();
return $this->renderSuccess(compact('list'));
}
@ -52,9 +54,136 @@ class Retail extends Controller
* @return Json
*/
public function purchase(): Json
{
return $this->renderSuccess(compact('detail'));
{ $model = new RetailModel();
$date = $this->request->post();
// print_r($date);
// exit;
// $detail = $model->where('retail_price_id',$date['retail_price_id'])->where('retail_status',10)->find();
$detail = $model::detail($date);
if(empty($detail)){
return $this->renderError("该会员不存在");
}
$data = [
'user_id'=>$this->user['user_id'],
'retail_order_number'=>$date['num'],
];
print_r($this->user['user_id']);
return $this->renderSuccess(compact('pk'));
}
// /**
// * 订单提交
// * @param string $mode
// * @return Json
// * @throws \think\db\exception\DataNotFoundException
// * @throws \think\db\exception\DbException
// * @throws \think\db\exception\ModelNotFoundException
// * @throws \cores\exception\BaseException
// */
// public function submit(string $mode = 'buyNow'): Json
// {
// return $this->order($mode);
// }
// public function order(string $mode = 'buyNow'): Json
// {
// if ($mode === 'buyNow') {
// return $this->buyNow();
// // } elseif ($mode === 'cart') {
// // return $this->cart();
// }
// return $this->renderError('结算模式不合法');
// }
// /**
// * 订单确认-立即购买
// * @return Json
// * @throws \think\db\exception\DataNotFoundException
// * @throws \think\db\exception\DbException
// * @throws \think\db\exception\ModelNotFoundException
// * @throws \cores\exception\BaseException
// */
// private function buyNow(): Json
// {
// // 实例化结算台服务
// $Checkout = new CheckoutService;
// // 订单结算api参数
// $params = $Checkout->setParam($this->getParam([
// 'goodsId' => 0,
// 'goodsSkuId' => '',
// 'goodsNum' => 0,
// ]));
// // print_r($params);
// // 表单验证
// if (!$this->getValidate()->scene('buyNow')->check($params)) {
// return $this->renderError($this->getValidate()->getError(), ['isCreated' => false]);
// }
// // 立即购买:获取订单商品列表
// $model = new RetailOrderModel;
// $goodsList = $model->getOrderGoodsListByNow(
// (int)$params['goodsId'],
// (string)$params['goodsSkuId'],
// (int)$params['goodsNum']
// );
// $merchantId = 0;
// foreach ($goodsList as $g) {
// $merchantId = $g['merchant_id'];
// }
// // 获取订单确认信息
// $orderInfo = $Checkout->onCheckout($goodsList);
// // echo "<pre>";
// // print_r($orderInfo['goodsList']->toArray());
// // exit;
// // print_r($this->request->isGet());
// if ($this->request->isGet()) {
// return $this->renderSuccess([
// 'order' => $orderInfo,
// 'personal' => $Checkout->getPersonal(),
// 'setting' => $Checkout->getSetting(),
// ]);
// }
// // 验证订单是否存在错误
// if ($Checkout->hasError()) {
// return $this->renderError($Checkout->getError(), ['isCreated' => false]);
// }
// // 创建订单 增加订单
// $orderInfo['merchantId'] = $merchantId;
// if ($merchantId) {
// $model = \app\store\model\Merchant::detail($merchantId, $this->storeId);
// $orderInfo['commission_ratio'] = $model['commission_ratio'];
// }
// //print_r($orderInfo);die;
// if (!$Checkout->createOrder($orderInfo)) {
// return $this->renderError($Checkout->getError() ?: '订单创建失败', ['isCreated' => false]);
// }
// // 返回状态
// return $this->renderSuccess(['orderId' => $Checkout->model['order_id']], '订单创建成功');
// }
// /**
// * 获取结算台验证器
// * @return CheckoutValidate
// */
// private function getValidate(): CheckoutValidate
// {
// if (is_null($this->validate)) {
// $this->validate = new CheckoutValidate;
// }
// return $this->validate;
// }
// /**
// * 订单结算提交的参数
// * @param array $define
// * @return array
// */
// private function getParam(array $define = []): array
// {
// return array_merge($define, $this->request->param());
// }
}

@ -20,4 +20,14 @@ class Retail extends RetailModel
return self::select();
}
public static function detail(array $where = [])
{
$where = [
'retail_price_id'=>$where['retail_price_id'],
'retail_status'=>10
];
return RetailModel::where($where)->select();
}
}

@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\model;
use app\common\model\RetailOrder as RetailOrderModel;
class RetailOrder extends RetailOrderModel
{
}

@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
class RetailOrder extends BaseModel
{
// 定义表名
protected $name = 'retail_order';
// 定义主键
protected $pk = 'retail_order_id';
// 开启自动写入时间戳
protected $autoWriteTimestamp = true;
// 创建时间字段
protected $createTime = 'create_time';
// 更新时间字段
protected $updateTime = 'update_time';
}

@ -45,6 +45,7 @@ class Retail extends Controller
public function add(): Json
{
$data = $this->postForm();
$id = $this->getStoreId();
if (!$data) {
return $this->renderError('缺少必要参数');
}

@ -28,7 +28,8 @@ class Retail extends RetailModel
* @return bool
*/
public function add($data): bool
{
{
$data['store_id'] = self::$storeId;
return $this->save($data);
}

Loading…
Cancel
Save