This commit is contained in:
2025-10-29 15:32:26 +08:00
parent d90614805b
commit b7462657cd
78921 changed files with 2753938 additions and 71 deletions

View File

@@ -0,0 +1,129 @@
<?php
namespace app\api\controller;
use app\model\order\OrderCreate as OrderCreateModel;
use think\facade\Cache;
use extend\exception\OrderException;
/**
* 订单创建
*/
class Ordercreate extends BaseOrderCreateApi
{
/**
* 创建订单
*/
public function create()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create = new OrderCreateModel();
$ishy = $this->params[ 'ishy' ] ?? '';//会员卡前端
if($ishy == 1){
$code = $this->params[ 'code' ] ?? '';//验证码
$code_key = $this->params[ 'code_key' ] ?? '';//验证码储存
$verify_data = Cache::get($code_key);
$member = model('member')->getInfo(['member_id'=>$this->member_id,'site_id'=>$this->site_id]);
if(empty($member['member_code'])) throw new OrderException('请先绑定会员卡');
if(empty($member['mobile'])) throw new OrderException('未绑定手机号码');
if (!empty($verify_data) && $verify_data['mobile'] == $member['mobile'] && $verify_data['code'] == $code) {
}else{
throw new OrderException('手机验证码错误');
}
}
$data = [
'order_key' => $this->params[ 'order_key' ] ?? '',
'is_balance' => $this->params[ 'is_balance' ] ?? 0,//是否使用余额
'is_point' => $this->params[ 'is_point' ] ?? 1,//是否使用积分
'coupon' => isset($this->params[ 'coupon' ]) && !empty($this->params[ 'coupon' ]) ? json_decode($this->params[ 'coupon' ], true) : [],
//会员卡项
'member_card_unit' => $this->params[ 'member_card_unit' ] ?? '',
//门店专属
'store_id' => $this->params[ 'store_id' ] ?? 0,
];
//会员日志
( new \app\model\member\Member() )->memberjournal($this->member_id,$this->site_id,1,'关注收银台');
$res = $order_create->setParam(array_merge($data, $this->getInputParam(), $this->getCommonParam(), $this->getDeliveryParam(), $this->getInvoiceParam()))->create();
return $this->response($res);
}
/**
* 计算
*/
public function calculate()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create = new OrderCreateModel();
$data = [
'order_key' => $this->params[ 'order_key' ] ?? '',//是否使用余额
'is_balance' => $this->params[ 'is_balance' ] ?? 0,//是否使用余额
'is_point' => $this->params[ 'is_point' ] ?? 1,//是否使用积分
'coupon' => isset($this->params[ 'coupon' ]) && !empty($this->params[ 'coupon' ]) ? json_decode($this->params[ 'coupon' ], true) : [],//优惠券
//会员卡项
'member_card_unit' => $this->params[ 'member_card_unit' ] ?? '',
//门店专属
'store_id' => $this->params[ 'store_id' ] ?? 0,
];
$res = $order_create->setParam(array_merge($data, $this->getCommonParam(), $this->getDeliveryParam(), $this->getInvoiceParam()))->confirm();
return $this->response($this->success($res));
}
/**
* 待支付订单 数据初始化
* @return string
*/
public function payment()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create = new OrderCreateModel();
$data = [
//商品项
'cart_ids' => $this->params[ 'cart_ids' ] ?? '',
'sku_id' => $this->params[ 'sku_id' ] ?? '',
'num' => $this->params[ 'num' ] ?? '',
//会员卡项
'member_goods_card' => isset($this->params[ 'member_goods_card' ]) && !empty($this->params[ 'member_goods_card' ]) ? json_decode($this->params[ 'member_goods_card' ], true) : [],
//接龙活动id
'jielong_id' => $this->params[ 'jielong_id' ] ?? '',
//会员卡项
'is_open_card' => $this->params[ 'is_open_card' ] ?? 0,
'member_card_unit' => $this->params[ 'member_card_unit' ] ?? '',
//门店专属
'store_id' => $this->params[ 'store_id' ] ?? 0,
];
if (!$data[ 'cart_ids' ] && !$data[ 'sku_id' ]) return $this->response($this->error('', '缺少必填参数商品数据'));
//会员日志
( new \app\model\member\Member() )->memberjournal($this->member_id,$this->site_id,1,'关注订单');
$res = $order_create->setParam(array_merge($data, $this->getCommonParam(), $this->getDeliveryParam()))->orderPayment();
return $this->response($this->success($res));
}
/**
* 查询订单可用的优惠券
* @return false|string
*/
public function getCouponList(){
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$order_create = new OrderCreateModel();
$data = [
'order_key' => $this->params[ 'order_key' ] ?? '',//是否使用余额
];
$res = $order_create->setParam(array_merge($data, $this->getCommonParam()))->getOrderCouponList();
return $this->response($this->success($res));
}
}