master
wangxinglong 2022-05-27 17:18:22 +08:00
parent e7c22405b7
commit c83dc9cd28
8 changed files with 145 additions and 92 deletions

View File

@ -670,5 +670,12 @@ if (!function_exists('resourceJoin')) {
return $domain.$string; 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 );
}
}

View File

@ -93,9 +93,7 @@ class Index extends Base
try { try {
CConfig::load('extra/statement', 'statement'); CConfig::load('extra/statement', 'statement');
$content = config('statement')['content'] ?? ''; $content = config('statement')['content'] ?? '';
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/"; $content = replaceStoragePath($content);
$content = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$content );
return $this->json(0, 'success', ['content' => $content]); return $this->json(0, 'success', ['content' => $content]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->json(5000, '获取免责声明失败'); return $this->json(5000, '获取免责声明失败');
@ -111,8 +109,8 @@ class Index extends Base
try { try {
CConfig::load('extra/purchaseinstructions', 'purchaseinstructions'); CConfig::load('extra/purchaseinstructions', 'purchaseinstructions');
$content = config('purchaseinstructions')['content'] ?? ''; $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]); return $this->json(0, 'success', ['content' => $content]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->json(5000, '获取失败'); return $this->json(5000, '获取失败');
@ -129,9 +127,7 @@ class Index extends Base
try { try {
CConfig::load('extra/addwechat', 'addwechat'); CConfig::load('extra/addwechat', 'addwechat');
$res = config('addwechat')?? []; $res = config('addwechat')?? [];
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/"; $res["content"] = replaceStoragePath($res["content"]);
$res["content"] = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$res["content"] );
return $this->json(0, 'success', $res); return $this->json(0, 'success', $res);
} catch (Exception $e) { } catch (Exception $e) {
return $this->json(5000, '获取添加微信失败'); return $this->json(5000, '获取添加微信失败');
@ -147,9 +143,7 @@ class Index extends Base
try { try {
CConfig::load('extra/about', 'about'); CConfig::load('extra/about', 'about');
$res = config('about')?? []; $res = config('about')?? [];
$pregRule = "/<[img|IMG].*?src=[\'|\"][\/storage]{1}(.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/"; $res["content"] = replaceStoragePath($res["content"]);
$res["content"] = preg_replace($pregRule, '<img src="' . $this->request->domain() . '/${1}" style="max-width:100%">', (string)$res["content"] );
return $this->json(0, 'success', $res); return $this->json(0, 'success', $res);
} catch (Exception $e) { } catch (Exception $e) {
return $this->json(5000, '获取关于我们失败'); return $this->json(5000, '获取关于我们失败');

View File

@ -7,9 +7,11 @@ use app\repository\OrderRepository;
use app\model\Order as OrderModel; use app\model\Order as OrderModel;
use Exception; use Exception;
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
use Intervention\Image\ImageManagerStatic;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\facade\Config as CConfig;
use think\response\Json; use think\response\Json;
/** /**
@ -20,6 +22,7 @@ use think\response\Json;
*/ */
class Order extends Base class Order extends Base
{ {
/** /**
* 创建订单 * 创建订单
* *
@ -32,6 +35,7 @@ class Order extends Base
$params = $this->request->param(); $params = $this->request->param();
$accountId = $this->request->user['user_id'] ?? 0; $accountId = $this->request->user['user_id'] ?? 0;
try { try {
$data = OrderRepository::getInstance()->createOrder($accountId, $params); $data = OrderRepository::getInstance()->createOrder($accountId, $params);
OrderRepository::getInstance()->updateSpuStock([]); OrderRepository::getInstance()->updateSpuStock([]);
@ -40,7 +44,7 @@ class Order extends Base
return $this->json(4000, $e->getMessage()); return $this->json(4000, $e->getMessage());
} catch (Exception $e) { } catch (Exception $e) {
OrderRepository::log('订单创建失败', $e, 'error', 'order'); OrderRepository::log('订单创建失败', $e, 'error', 'order');
return $this->json(5000, '订单创建失败'); return $this->json(5000, '订单创建失败'.$e->getMessage());
} }
} }
return $this->json(4002, '请求错误'); 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]);
} }
} }

View File

@ -231,7 +231,7 @@ class User extends Base
'id', 'coding', 'real_name', 'nickname', 'headimgurl', 'mobile', 'id', 'coding', 'real_name', 'nickname', 'headimgurl', 'mobile',
// 'province', 'city', 'county', 'country', 'birthday', 'gender' // 'province', 'city', 'county', 'country', 'birthday', 'gender'
'score', 'status', 'invite_code', 'channel', '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(); $repo = AccountRepository::getInstance();
$user = $repo->findById($accountId, $fields); $user = $repo->findById($accountId, $fields);

View File

@ -153,8 +153,8 @@ class OrderRepository extends Repository
throw new RepositoryException('收货地址不能为空'); throw new RepositoryException('收货地址不能为空');
} }
if (!isset($data['phone']) || empty($data['phone'])) { if (!isset($data['phone']) || empty($data['phone'])||!preg_match("/^1[3456789]{1}\d{9}$/",$data['phone'])) {
throw new RepositoryException('收货联系电话不能为空'); throw new RepositoryException('收货联系电话不能为空或格式不正确');
} }
if (!isset($data['contacts']) || empty($data['contacts'])) { if (!isset($data['contacts']) || empty($data['contacts'])) {
throw new RepositoryException('收货联系人不能为空'); throw new RepositoryException('收货联系人不能为空');
@ -299,11 +299,12 @@ class OrderRepository extends Repository
$dataSku = $data['sku_list'];//商品sku coding=>num 商品数量 $dataSku = $data['sku_list'];//商品sku coding=>num 商品数量
$skuList = SpuRepository::getInstance()->listBySkuCoding(array_keys($dataSku), true); $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');
$skuPriceList = $skuList->column('original_price', 'coding'); // if (isset($data['is_only']) && $data['is_only'] > Spu::COMMON_OFF) {
} else { // $skuPriceList = $skuList->column('original_price', 'coding');
$skuPriceList = $skuList->column('price', 'coding'); // } else {
} // $skuPriceList = $skuList->column('price', 'coding');
// }
$skuScoreList = $skuList->column('score', 'coding');//商品规格=》积分 $skuScoreList = $skuList->column('score', 'coding');//商品规格=》积分
$skuStockList = $skuList->column('stock', 'coding'); $skuStockList = $skuList->column('stock', 'coding');
$totalPrice = 0;//商品原总价 单位(元) 未做任何优惠 $totalPrice = 0;//商品原总价 单位(元) 未做任何优惠
@ -338,28 +339,29 @@ class OrderRepository extends Repository
(new Sku())->saveAll($updateSkuStock); (new Sku())->saveAll($updateSkuStock);
$freight = 0;//运费(元) // $freight = 0;//运费(元)
// 邮寄方式 // // 邮寄方式
if ($data['pick_self'] == Order::COMMON_OFF) { // if ($data['pick_self'] == Order::COMMON_OFF) {
// 快递公司默认运费 // // 快递公司默认运费
if (isset($data['express_code']) && !empty($data['express_code'])) { // if (isset($data['express_code']) && !empty($data['express_code'])) {
$freight = Express::getDefaultFreight($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'])) { //$realTotalPrice = $totalPrice - $data['coupon_price'];//实际应支付=商品总价-优惠券金额
throw new RepositoryException('收货地址不存在'); $realTotalPrice = $totalPrice;//实际应支付=商品总价-优惠券金额
}
$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 = $realTotalPrice <= 0 ? 0 : $realTotalPrice; $realTotalPrice = $realTotalPrice <= 0 ? 0 : $realTotalPrice;
$realTotalPrice += $freight;//加运费 // $realTotalPrice += $freight;//加运费
$insert = []; $insert = [];
$time = time(); $time = time();
@ -370,12 +372,12 @@ class OrderRepository extends Repository
$payType = Order::PAY_TYPE_WECHAT; $payType = Order::PAY_TYPE_WECHAT;
// 积分支付 // 积分支付
if ($data['is_score'] > 0) { // if ($data['is_score'] > 0) {
if ($account['score'] < $totalScore) { // if ($account['score'] < $totalScore) {
throw new RepositoryException('积分不足'); // throw new RepositoryException('积分不足');
} // }
$payType = Order::PAY_TYPE_SCORE; // $payType = Order::PAY_TYPE_SCORE;
} // }
$create = [ $create = [
'coding' => generateCode(), 'coding' => generateCode(),
@ -383,26 +385,32 @@ class OrderRepository extends Repository
'original_price' => $totalPrice, 'original_price' => $totalPrice,
'price' => $realTotalPrice, 'price' => $realTotalPrice,
'pay_type' => $payType,//支付方式 'pay_type' => $payType,//支付方式
'status' => self::STATUS_WAITING, 'status' => self::STATUS_ORDER_PLACED,
'created_at' => $now, 'created_at' => $now,
'score' => $totalScore,//使用积分 'score' => $totalScore,//使用积分
'expired_at' => $expired, 'expired_at' => $expired,
'address_id' => $data['address_id'] ?? 0, 'address_id' => $data['address_id'] ?? 0,
'address' => $addressInfo, //'address' => $addressInfo,
'remarks' => $data['remarks'] ?? '', 'remarks' => $data['remarks'] ?? '',
'express_code' => $data['express_code'], 'express_code' => $data['express_code']??'',
'express_name' => $data['express_name'] ?? '', 'express_name' => $data['express_name'] ?? '',
'pick_self' => $data['pick_self'], 'pick_self' => $data['pick_self'] ??0,
'coupon_id' => $data['coupon_id'] ?? 0, 'coupon_id' => $data['coupon_id'] ?? 0,
'freight' => $freight, 'freight' => 0,
'coupon_price' => $data['coupon_price'] ?? 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_only' => isset($data['is_only']) && $data['is_only'] > 0 ? 1 : 0,
'is_score' => $data['is_score'] ?? 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) { if ($realTotalPrice == 0) {
$create['status'] = self::STATUS_PAID; $create['status'] = self::STATUS_ORDER_PLACED;
$create['paid_at'] = $now; $create['paid_at'] = $now;
} }
@ -411,26 +419,26 @@ class OrderRepository extends Repository
throw new RepositoryException('订单创建失败,请稍后重试'); throw new RepositoryException('订单创建失败,请稍后重试');
} }
// 优惠券状态变更 // // 优惠券状态变更
if ($data['coupon_id'] > 0 && $data['coupon_price'] > 0) { // if ($data['coupon_id'] > 0 && $data['coupon_price'] > 0) {
AccountCoupon::use($accountId, $data['coupon_id'], $order['coding']); // AccountCoupon::use($accountId, $data['coupon_id'], $order['coding']);
} // }
// 创建活动商品订单 // 创建活动商品订单
// OrderRepository::getInstance()->createActivityOrder($accountId, $order->coding, $skuArr->toArray()); // OrderRepository::getInstance()->createActivityOrder($accountId, $order->coding, $skuArr->toArray());
if ($realTotalPrice > 0) { // if ($realTotalPrice > 0) {
//创建支付记录 // //创建支付记录
PaymentLog::create([ // PaymentLog::create([
'account_id' => $accountId, // 'account_id' => $accountId,
'order_coding' => $order['coding'], // 'order_coding' => $order['coding'],
'created_at' => $now, // 'created_at' => $now,
'type' => 'order', // 'type' => 'order',
'amount' => $order['price'], // 'amount' => $order['price'],
]); // ]);
} // }
$order->needPay = $realTotalPrice > 0;//是否需要付款 // $order->needPay = $realTotalPrice > 0;//是否需要付款
$orderHasVirtual = 0;//是否拥有虚拟商品 $orderHasVirtual = 0;//是否拥有虚拟商品
$skuIds = [];//当前订单涉及到的skuID $skuIds = [];//当前订单涉及到的skuID
@ -479,30 +487,35 @@ class OrderRepository extends Repository
throw new RepositoryException('订单商品保存失败'); throw new RepositoryException('订单商品保存失败');
} }
if ($realTotalPrice > 0) { // if ($realTotalPrice > 0) {
//统一下单 // //统一下单
$res = $this->wechatMiniPay($order->coding, $account->openid, Math::yuan2Fen($realTotalPrice)); // $res = $this->wechatMiniPay($order->coding, $account->openid, Math::yuan2Fen($realTotalPrice));
$order->save(['prepay_id' => $res['prepay_id']]); // $order->save(['prepay_id' => $res['prepay_id']]);
//
//生成小程序支付请求的参数 // //生成小程序支付请求的参数
$order->payment_params = $this->miniPayReqParams($res['prepay_id']); // $order->payment_params = $this->miniPayReqParams($res['prepay_id']);
} // }
// 积分订单 扣减积分并记录 // 积分订单 扣减积分并记录
if ($totalScore > 0) { // if ($totalScore > 0) {
AccountDataLog::log($accountId, // AccountDataLog::log($accountId,
'积分商品下单', -$totalScore, // '积分商品下单', -$totalScore,
AccountDataLog::TYPE_SCORE, // AccountDataLog::TYPE_SCORE,
AccountDataLog::ACTION_ORDER, // AccountDataLog::ACTION_ORDER,
$account['score'] - $totalScore); // $account['score'] - $totalScore);
$account->score = Db::raw('`score` - '.$totalScore); // $account->score = Db::raw('`score` - '.$totalScore);
} // }
$account->mobile = $data["phone"];
$account->address = $data["address"];
$account->contacts = $data["contacts"];
$account->save(); $account->save();
if ($realTotalPrice == 0) { // if ($realTotalPrice == 0) {
// 设为已付款 // // 设为已付款
$this->afterPaid($accountId, $order['coding']); // $this->afterPaid($accountId, $order['coding']);
} // }
// 设为已付款
$this->afterPaid($accountId, $order['coding']);
Db::commit(); Db::commit();
return $order; return $order;
@ -513,7 +526,7 @@ class OrderRepository extends Repository
//回滚 //回滚
Db::rollback(); Db::rollback();
self::log('订单创建失败', $e, 'error', 'order'); 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) public function afterPaid(int $accountId, string $orderCoding)
{ {
OrderSku::setPaid($orderCoding);//订单商品 OrderSku::setPaid($orderCoding);//订单商品
OrderActivity::setPaid($orderCoding);//活动订单 //OrderActivity::setPaid($orderCoding);//活动订单
OrderGroupList::setPaid($orderCoding);//订单拼团列表 // OrderGroupList::setPaid($orderCoding);//订单拼团列表
// 付款后 所有商品销量添加 // 付款后 所有商品销量添加
$this->updateAmount($orderCoding); $this->updateAmount($orderCoding);

View File

@ -150,7 +150,6 @@ trait ShoppingCartTrait
if (!$item = ShoppingCart::where('id', $id)->find()) { if (!$item = ShoppingCart::where('id', $id)->find()) {
throw new RepositoryException('记录不存在'); throw new RepositoryException('记录不存在');
} }
return $item->save(['num' => $num]); return $item->save(['num' => $num]);
} }

View File

@ -1,4 +1,5 @@
<IfModule mod_rewrite.c> <IfModule mod_rewrite.c>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
Options +FollowSymlinks -Multiviews Options +FollowSymlinks -Multiviews
RewriteEngine On RewriteEngine On

BIN
public/static/HYa3gj.ttf Normal file

Binary file not shown.