setter
parent
e7c22405b7
commit
c83dc9cd28
|
@ -670,5 +670,12 @@ if (!function_exists('resourceJoin')) {
|
|||
return $domain.$string;
|
||||
}
|
||||
}
|
||||
if (!function_exists('replaceStoragePath'))
|
||||
{
|
||||
function replaceStoragePath ($content){
|
||||
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
|
||||
return preg_replace($pregRule, '<img src="' . request()->domain() . '/${1}" style="max-width:100%">', (string)$content );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -93,9 +93,7 @@ class Index extends Base
|
|||
try {
|
||||
CConfig::load('extra/statement', 'statement');
|
||||
$content = config('statement')['content'] ?? '';
|
||||
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
|
||||
$content = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$content );
|
||||
|
||||
$content = replaceStoragePath($content);
|
||||
return $this->json(0, 'success', ['content' => $content]);
|
||||
} catch (Exception $e) {
|
||||
return $this->json(5000, '获取免责声明失败');
|
||||
|
@ -111,8 +109,8 @@ class Index extends Base
|
|||
try {
|
||||
CConfig::load('extra/purchaseinstructions', 'purchaseinstructions');
|
||||
$content = config('purchaseinstructions')['content'] ?? '';
|
||||
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
|
||||
$content = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$content );
|
||||
|
||||
$content = replaceStoragePath($content);
|
||||
return $this->json(0, 'success', ['content' => $content]);
|
||||
} catch (Exception $e) {
|
||||
return $this->json(5000, '获取失败');
|
||||
|
@ -129,9 +127,7 @@ class Index extends Base
|
|||
try {
|
||||
CConfig::load('extra/addwechat', 'addwechat');
|
||||
$res = config('addwechat')?? [];
|
||||
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
|
||||
$res["content"] = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$res["content"] );
|
||||
|
||||
$res["content"] = replaceStoragePath($res["content"]);
|
||||
return $this->json(0, 'success', $res);
|
||||
} catch (Exception $e) {
|
||||
return $this->json(5000, '获取添加微信失败');
|
||||
|
@ -147,9 +143,7 @@ class Index extends Base
|
|||
try {
|
||||
CConfig::load('extra/about', 'about');
|
||||
$res = config('about')?? [];
|
||||
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
|
||||
$res["content"] = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$res["content"] );
|
||||
|
||||
$res["content"] = replaceStoragePath($res["content"]);
|
||||
return $this->json(0, 'success', $res);
|
||||
} catch (Exception $e) {
|
||||
return $this->json(5000, '获取关于我们失败');
|
||||
|
|
|
@ -7,9 +7,11 @@ use app\repository\OrderRepository;
|
|||
use app\model\Order as OrderModel;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Intervention\Image\ImageManagerStatic;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Config as CConfig;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
|
@ -20,6 +22,7 @@ use think\response\Json;
|
|||
*/
|
||||
class Order extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*
|
||||
|
@ -32,6 +35,7 @@ class Order extends Base
|
|||
$params = $this->request->param();
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
||||
|
||||
try {
|
||||
$data = OrderRepository::getInstance()->createOrder($accountId, $params);
|
||||
OrderRepository::getInstance()->updateSpuStock([]);
|
||||
|
@ -40,7 +44,7 @@ class Order extends Base
|
|||
return $this->json(4000, $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
OrderRepository::log('订单创建失败', $e, 'error', 'order');
|
||||
return $this->json(5000, '订单创建失败');
|
||||
return $this->json(5000, '订单创建失败'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
return $this->json(4002, '请求错误');
|
||||
|
@ -428,9 +432,44 @@ class Order extends Base
|
|||
}
|
||||
|
||||
|
||||
public function shopCartCartOrder()
|
||||
//生成订单图片
|
||||
public function orderQrCode()
|
||||
{
|
||||
$id = input("id/d",0);
|
||||
$order = OrderModel::findById($id);
|
||||
if(empty($order)){
|
||||
return $this->json(4001,"订单不存在");
|
||||
}
|
||||
$orderCoding = $order->coding;
|
||||
CConfig::load('extra/addwechat', "addwechat");
|
||||
$addwechat = config("addwechat");
|
||||
$qrImg = public_path() . ($addwechat["wechat"] ?? '');
|
||||
$content = replaceStoragePath($addwechat['content']??'');
|
||||
|
||||
if(!is_file($qrImg)){
|
||||
return $this->json(4001,"生成订单二维码图片失败");
|
||||
}
|
||||
if(!is_writable(public_path()."/storage/")){
|
||||
return $this->json("上传文件夹需要写入权限");
|
||||
}
|
||||
if(!is_dir( public_path()."/storage/order_qr_code/")){
|
||||
mkdir(public_path()."/storage/order_qr_code");
|
||||
}
|
||||
|
||||
$savePath = "/storage/order_qr_code/" . $orderCoding . ".png";
|
||||
ImageManagerStatic::canvas(800, 700, '#fff')
|
||||
->insert(ImageManagerStatic::make($qrImg)->resize(500,500),"top-left",150,0)
|
||||
->text("订单:".$orderCoding,400,600, function ($font){
|
||||
$font->file(public_path() . "/static/HYa3gj.ttf");
|
||||
$font->size(46);
|
||||
$font->align("center");
|
||||
$font->valign("center");
|
||||
})
|
||||
|
||||
// ->insert(ImageManagerStatic::make($mpCode)->resize(380, 380), 'bottom-right', 560, 723)
|
||||
// ->encode('data-url');
|
||||
->save(public_path() . $savePath);
|
||||
return $this->json(0, "success", ["path" => $savePath, "content" => $content]);
|
||||
}
|
||||
|
||||
}
|
|
@ -231,7 +231,7 @@ class User extends Base
|
|||
'id', 'coding', 'real_name', 'nickname', 'headimgurl', 'mobile',
|
||||
// 'province', 'city', 'county', 'country', 'birthday', 'gender'
|
||||
'score', 'status', 'invite_code', 'channel',
|
||||
'is_active', "continuity_sign", "last_sign_online", 'phone_active'
|
||||
'is_active', "continuity_sign", "last_sign_online", 'phone_active','address','contacts'
|
||||
];
|
||||
$repo = AccountRepository::getInstance();
|
||||
$user = $repo->findById($accountId, $fields);
|
||||
|
|
|
@ -153,8 +153,8 @@ class OrderRepository extends Repository
|
|||
throw new RepositoryException('收货地址不能为空');
|
||||
}
|
||||
|
||||
if (!isset($data['phone']) || empty($data['phone'])) {
|
||||
throw new RepositoryException('收货联系电话不能为空');
|
||||
if (!isset($data['phone']) || empty($data['phone'])||!preg_match("/^1[3456789]{1}\d{9}$/",$data['phone'])) {
|
||||
throw new RepositoryException('收货联系电话不能为空或格式不正确');
|
||||
}
|
||||
if (!isset($data['contacts']) || empty($data['contacts'])) {
|
||||
throw new RepositoryException('收货联系人不能为空');
|
||||
|
@ -299,11 +299,12 @@ class OrderRepository extends Repository
|
|||
$dataSku = $data['sku_list'];//商品sku coding=>num 商品数量
|
||||
|
||||
$skuList = SpuRepository::getInstance()->listBySkuCoding(array_keys($dataSku), true);
|
||||
if (isset($data['is_only']) && $data['is_only'] > Spu::COMMON_OFF) {
|
||||
$skuPriceList = $skuList->column('original_price', 'coding');
|
||||
} else {
|
||||
$skuPriceList = $skuList->column('price', 'coding');
|
||||
}
|
||||
$skuPriceList = $skuList->column('original_price', 'coding');
|
||||
// if (isset($data['is_only']) && $data['is_only'] > Spu::COMMON_OFF) {
|
||||
// $skuPriceList = $skuList->column('original_price', 'coding');
|
||||
// } else {
|
||||
// $skuPriceList = $skuList->column('price', 'coding');
|
||||
// }
|
||||
$skuScoreList = $skuList->column('score', 'coding');//商品规格=》积分
|
||||
$skuStockList = $skuList->column('stock', 'coding');
|
||||
$totalPrice = 0;//商品原总价 单位(元) 未做任何优惠
|
||||
|
@ -338,28 +339,29 @@ class OrderRepository extends Repository
|
|||
|
||||
(new Sku())->saveAll($updateSkuStock);
|
||||
|
||||
$freight = 0;//运费(元)
|
||||
// 邮寄方式
|
||||
if ($data['pick_self'] == Order::COMMON_OFF) {
|
||||
// 快递公司默认运费
|
||||
if (isset($data['express_code']) && !empty($data['express_code'])) {
|
||||
$freight = Express::getDefaultFreight($data['express_code']);
|
||||
}
|
||||
// $freight = 0;//运费(元)
|
||||
// // 邮寄方式
|
||||
// if ($data['pick_self'] == Order::COMMON_OFF) {
|
||||
// // 快递公司默认运费
|
||||
// if (isset($data['express_code']) && !empty($data['express_code'])) {
|
||||
// $freight = Express::getDefaultFreight($data['express_code']);
|
||||
// }
|
||||
//
|
||||
// if (!$address = AccountAddress::findById($data['address_id'])) {
|
||||
// throw new RepositoryException('收货地址不存在');
|
||||
// }
|
||||
//
|
||||
// $addressInfo = sprintf("%s,%s,%s %s %s %s", $address['name'], $address['phone'],
|
||||
// $address['province_str'], $address['city_str'], $address['county_str'], $address['address']);
|
||||
// } else {
|
||||
// $addressInfo = '自提';
|
||||
// }
|
||||
|
||||
if (!$address = AccountAddress::findById($data['address_id'])) {
|
||||
throw new RepositoryException('收货地址不存在');
|
||||
}
|
||||
|
||||
$addressInfo = sprintf("%s,%s,%s %s %s %s", $address['name'], $address['phone'],
|
||||
$address['province_str'], $address['city_str'], $address['county_str'], $address['address']);
|
||||
} else {
|
||||
$addressInfo = '自提';
|
||||
}
|
||||
|
||||
$realTotalPrice = $totalPrice - $data['coupon_price'];//实际应支付=商品总价-优惠券金额
|
||||
//$realTotalPrice = $totalPrice - $data['coupon_price'];//实际应支付=商品总价-优惠券金额
|
||||
$realTotalPrice = $totalPrice;//实际应支付=商品总价-优惠券金额
|
||||
$realTotalPrice = $realTotalPrice <= 0 ? 0 : $realTotalPrice;
|
||||
|
||||
$realTotalPrice += $freight;//加运费
|
||||
// $realTotalPrice += $freight;//加运费
|
||||
|
||||
$insert = [];
|
||||
$time = time();
|
||||
|
@ -370,12 +372,12 @@ class OrderRepository extends Repository
|
|||
$payType = Order::PAY_TYPE_WECHAT;
|
||||
|
||||
// 积分支付
|
||||
if ($data['is_score'] > 0) {
|
||||
if ($account['score'] < $totalScore) {
|
||||
throw new RepositoryException('积分不足');
|
||||
}
|
||||
$payType = Order::PAY_TYPE_SCORE;
|
||||
}
|
||||
// if ($data['is_score'] > 0) {
|
||||
// if ($account['score'] < $totalScore) {
|
||||
// throw new RepositoryException('积分不足');
|
||||
// }
|
||||
// $payType = Order::PAY_TYPE_SCORE;
|
||||
// }
|
||||
|
||||
$create = [
|
||||
'coding' => generateCode(),
|
||||
|
@ -383,26 +385,32 @@ class OrderRepository extends Repository
|
|||
'original_price' => $totalPrice,
|
||||
'price' => $realTotalPrice,
|
||||
'pay_type' => $payType,//支付方式
|
||||
'status' => self::STATUS_WAITING,
|
||||
'status' => self::STATUS_ORDER_PLACED,
|
||||
'created_at' => $now,
|
||||
'score' => $totalScore,//使用积分
|
||||
'expired_at' => $expired,
|
||||
'address_id' => $data['address_id'] ?? 0,
|
||||
'address' => $addressInfo,
|
||||
//'address' => $addressInfo,
|
||||
'remarks' => $data['remarks'] ?? '',
|
||||
'express_code' => $data['express_code'],
|
||||
'express_code' => $data['express_code']??'',
|
||||
'express_name' => $data['express_name'] ?? '',
|
||||
'pick_self' => $data['pick_self'],
|
||||
'pick_self' => $data['pick_self'] ??0,
|
||||
'coupon_id' => $data['coupon_id'] ?? 0,
|
||||
'freight' => $freight,
|
||||
'freight' => 0,
|
||||
'coupon_price' => $data['coupon_price'] ?? 0,
|
||||
'phone' => $address['phone'] ?? $data['pick_self_phone'],
|
||||
//'phone' => $address['phone'] ?? $data['pick_self_phone'],
|
||||
'is_only' => isset($data['is_only']) && $data['is_only'] > 0 ? 1 : 0,
|
||||
'is_score' => $data['is_score'] ?? 0,
|
||||
|
||||
'wedding_date' => $data['wedding_date'] ?? null,
|
||||
'expected_delivery_date' => $data['expected_delivery_date'] ?? null,
|
||||
'address' => $data['address'] ?? '',
|
||||
'phone' => $data['phone'] ?? '',
|
||||
'contacts' => $data['contacts'] ?? '',
|
||||
];
|
||||
|
||||
if ($realTotalPrice == 0) {
|
||||
$create['status'] = self::STATUS_PAID;
|
||||
$create['status'] = self::STATUS_ORDER_PLACED;
|
||||
$create['paid_at'] = $now;
|
||||
}
|
||||
|
||||
|
@ -411,26 +419,26 @@ class OrderRepository extends Repository
|
|||
throw new RepositoryException('订单创建失败,请稍后重试');
|
||||
}
|
||||
|
||||
// 优惠券状态变更
|
||||
if ($data['coupon_id'] > 0 && $data['coupon_price'] > 0) {
|
||||
AccountCoupon::use($accountId, $data['coupon_id'], $order['coding']);
|
||||
}
|
||||
// // 优惠券状态变更
|
||||
// if ($data['coupon_id'] > 0 && $data['coupon_price'] > 0) {
|
||||
// AccountCoupon::use($accountId, $data['coupon_id'], $order['coding']);
|
||||
// }
|
||||
|
||||
// 创建活动商品订单
|
||||
// OrderRepository::getInstance()->createActivityOrder($accountId, $order->coding, $skuArr->toArray());
|
||||
|
||||
if ($realTotalPrice > 0) {
|
||||
//创建支付记录
|
||||
PaymentLog::create([
|
||||
'account_id' => $accountId,
|
||||
'order_coding' => $order['coding'],
|
||||
'created_at' => $now,
|
||||
'type' => 'order',
|
||||
'amount' => $order['price'],
|
||||
]);
|
||||
}
|
||||
// if ($realTotalPrice > 0) {
|
||||
// //创建支付记录
|
||||
// PaymentLog::create([
|
||||
// 'account_id' => $accountId,
|
||||
// 'order_coding' => $order['coding'],
|
||||
// 'created_at' => $now,
|
||||
// 'type' => 'order',
|
||||
// 'amount' => $order['price'],
|
||||
// ]);
|
||||
// }
|
||||
|
||||
$order->needPay = $realTotalPrice > 0;//是否需要付款
|
||||
// $order->needPay = $realTotalPrice > 0;//是否需要付款
|
||||
$orderHasVirtual = 0;//是否拥有虚拟商品
|
||||
|
||||
$skuIds = [];//当前订单涉及到的skuID
|
||||
|
@ -479,30 +487,35 @@ class OrderRepository extends Repository
|
|||
throw new RepositoryException('订单商品保存失败');
|
||||
}
|
||||
|
||||
if ($realTotalPrice > 0) {
|
||||
//统一下单
|
||||
$res = $this->wechatMiniPay($order->coding, $account->openid, Math::yuan2Fen($realTotalPrice));
|
||||
$order->save(['prepay_id' => $res['prepay_id']]);
|
||||
|
||||
//生成小程序支付请求的参数
|
||||
$order->payment_params = $this->miniPayReqParams($res['prepay_id']);
|
||||
}
|
||||
// if ($realTotalPrice > 0) {
|
||||
// //统一下单
|
||||
// $res = $this->wechatMiniPay($order->coding, $account->openid, Math::yuan2Fen($realTotalPrice));
|
||||
// $order->save(['prepay_id' => $res['prepay_id']]);
|
||||
//
|
||||
// //生成小程序支付请求的参数
|
||||
// $order->payment_params = $this->miniPayReqParams($res['prepay_id']);
|
||||
// }
|
||||
|
||||
// 积分订单 扣减积分并记录
|
||||
if ($totalScore > 0) {
|
||||
AccountDataLog::log($accountId,
|
||||
'积分商品下单', -$totalScore,
|
||||
AccountDataLog::TYPE_SCORE,
|
||||
AccountDataLog::ACTION_ORDER,
|
||||
$account['score'] - $totalScore);
|
||||
$account->score = Db::raw('`score` - '.$totalScore);
|
||||
}
|
||||
// if ($totalScore > 0) {
|
||||
// AccountDataLog::log($accountId,
|
||||
// '积分商品下单', -$totalScore,
|
||||
// AccountDataLog::TYPE_SCORE,
|
||||
// AccountDataLog::ACTION_ORDER,
|
||||
// $account['score'] - $totalScore);
|
||||
// $account->score = Db::raw('`score` - '.$totalScore);
|
||||
// }
|
||||
$account->mobile = $data["phone"];
|
||||
$account->address = $data["address"];
|
||||
$account->contacts = $data["contacts"];
|
||||
$account->save();
|
||||
|
||||
if ($realTotalPrice == 0) {
|
||||
// 设为已付款
|
||||
$this->afterPaid($accountId, $order['coding']);
|
||||
}
|
||||
// if ($realTotalPrice == 0) {
|
||||
// // 设为已付款
|
||||
// $this->afterPaid($accountId, $order['coding']);
|
||||
// }
|
||||
// 设为已付款
|
||||
$this->afterPaid($accountId, $order['coding']);
|
||||
|
||||
Db::commit();
|
||||
return $order;
|
||||
|
@ -513,7 +526,7 @@ class OrderRepository extends Repository
|
|||
//回滚
|
||||
Db::rollback();
|
||||
self::log('订单创建失败', $e, 'error', 'order');
|
||||
throw new RepositoryException('订单创建失败');
|
||||
throw new RepositoryException('订单创建失败'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -860,8 +873,8 @@ class OrderRepository extends Repository
|
|||
public function afterPaid(int $accountId, string $orderCoding)
|
||||
{
|
||||
OrderSku::setPaid($orderCoding);//订单商品
|
||||
OrderActivity::setPaid($orderCoding);//活动订单
|
||||
OrderGroupList::setPaid($orderCoding);//订单拼团列表
|
||||
//OrderActivity::setPaid($orderCoding);//活动订单
|
||||
// OrderGroupList::setPaid($orderCoding);//订单拼团列表
|
||||
|
||||
// 付款后 所有商品销量添加
|
||||
$this->updateAmount($orderCoding);
|
||||
|
|
|
@ -150,7 +150,6 @@ trait ShoppingCartTrait
|
|||
if (!$item = ShoppingCart::where('id', $id)->find()) {
|
||||
throw new RepositoryException('记录不存在');
|
||||
}
|
||||
|
||||
return $item->save(['num' => $num]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
||||
Options +FollowSymlinks -Multiviews
|
||||
RewriteEngine On
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue