|
|
@@ -36,184 +36,21 @@ class OrderController extends BaseController
|
|
|
public function actionCreateOrder()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
|
|
|
- $orderType = $post['orderType'] ?? 1;
|
|
|
$post['sjId'] = $this->sjId;
|
|
|
$post['shopId'] = $this->shopId;
|
|
|
$post['payWay'] = $this->isWx == true ? 0 : 1;
|
|
|
$now = time();
|
|
|
- $expireTime = $now + 1800;//订单30分钟后过期
|
|
|
+ //订单30分钟后过期
|
|
|
+ $expireTime = $now + 1800;
|
|
|
$post['deadline'] = $expireTime;
|
|
|
- $post['fromType'] = 1;//商城
|
|
|
- $customId = $post['customId'] ?? 0;
|
|
|
- if (!empty($customId)) {
|
|
|
- $customInfo = CustomClass::getCustomInfo($customId);
|
|
|
- CustomClass::valid($customInfo, $this->shopId);
|
|
|
- $post['customId'] = $customId;
|
|
|
- }
|
|
|
- //门店订单
|
|
|
- $post['store'] = 1;
|
|
|
- //员工信息
|
|
|
- $shopAdmin = $this->shopAdmin->attributes;
|
|
|
- $shopAdminName = $shopAdmin['name'] ?? '';
|
|
|
- $post['shopAdminName'] = $shopAdminName;
|
|
|
- $post['shopAdminId'] = $this->shopAdminId;
|
|
|
-
|
|
|
- $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
|
|
|
-
|
|
|
- if ($orderType == 1) {
|
|
|
- //$orderType = 1 成品订单
|
|
|
- $goodsInfo = $post['goodsInfo'] ?? '';
|
|
|
- $goodsInfoArr = json_decode($goodsInfo, true);
|
|
|
- if (empty($goodsInfoArr)) {
|
|
|
- util::fail('请选择商品');
|
|
|
- }
|
|
|
- //总的商品金额
|
|
|
- $totalGoodsPrice = 0;
|
|
|
- $orderGoods = [];
|
|
|
- foreach ($goodsInfoArr as $key => $currentGoods) {
|
|
|
- $currentGoodsId = $currentGoods['goodsId'];
|
|
|
- $currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
|
|
|
- if (empty($currentGoodsInfo)) {
|
|
|
- util::fail('没有找到商品');
|
|
|
- }
|
|
|
- $goodsStyleId = $currentGoods['goodsStyleId'];
|
|
|
- $goodsNum = $currentGoods['goodsNum'];
|
|
|
- //计算总金额
|
|
|
- $unitPrice = $currentGoodsInfo['price'];
|
|
|
- $goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
|
|
|
- if (!empty($goodsStyleId)) {
|
|
|
- $idKeyStyleList = array_column($goodsStyleList, null, 'id');
|
|
|
- if (empty($goodsStyleList)) {
|
|
|
- util::fail('商品款式没有找到');
|
|
|
- }
|
|
|
- $styleIdList = array_keys(array_column($goodsStyleList, null, "id"));
|
|
|
- if (in_array($goodsStyleId, $styleIdList) == false) {
|
|
|
- util::fail('商品款式没有找到!');
|
|
|
- }
|
|
|
- if (isset($idKeyStyleList[$goodsStyleId]['price']) == false) {
|
|
|
- util::fail('没有找到多款式的价格');
|
|
|
- }
|
|
|
- $unitPrice = $idKeyStyleList[$goodsStyleId]['price'];
|
|
|
- }
|
|
|
- $goodsPrice = $unitPrice * $goodsNum;
|
|
|
- $totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
|
|
|
- $orderGoods[] = [
|
|
|
- 'goodsId' => $currentGoodsId,
|
|
|
- 'userId' => $this->adminId,
|
|
|
- 'sjId' => $this->sjId,
|
|
|
- 'title' => $currentGoodsInfo['goodsName'],
|
|
|
- 'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
|
|
|
- 'unitPrice' => $unitPrice,
|
|
|
- 'num' => $goodsNum,
|
|
|
- 'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
|
|
|
- 'goodsStyleId' => $goodsStyleId,
|
|
|
- 'createTime' => date("Y-m-d H:i:s"),
|
|
|
- ];
|
|
|
+ //商城
|
|
|
+ $post['fromType'] = 1;
|
|
|
|
|
|
- }
|
|
|
- $user = $this->custom;
|
|
|
- $post['bookName'] = isset($user['name']) ? $user['name'] : '';
|
|
|
- $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
|
|
|
- $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
|
|
|
- $post['bookMobile'] = $bookMobile;
|
|
|
-
|
|
|
- //计算运费
|
|
|
- $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
|
|
|
- $sendCost = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
|
|
|
- //按距离计算运费并且客户要求送的
|
|
|
- //运费计算方式
|
|
|
- //$freightType = 0;
|
|
|
- //if ($freightType == 0 && $needSend == 1) {
|
|
|
- //$lat = $post['latitude']??'';//收货人纬度
|
|
|
- //$lng = $post['longitude']??'';//收货人经度
|
|
|
- //$respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
|
|
|
- //$sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
|
|
|
- //}
|
|
|
- $post['sendCost'] = $sendCost;
|
|
|
- $currentPrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
|
|
|
- $post['prePrice'] = $currentPrice;
|
|
|
- if (isset($post['modifyPrice'])) {
|
|
|
- //商家打折,修改金额
|
|
|
- $modifyPrice = $post['modifyPrice'] ?? 0;
|
|
|
- if ($modifyPrice > $currentPrice) {
|
|
|
- util::fail('实收金额大于订单总金额');
|
|
|
- }
|
|
|
- if ($modifyPrice < $currentPrice) {
|
|
|
- $post['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
|
|
|
- $post['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
- $currentPrice = $modifyPrice;
|
|
|
- }
|
|
|
- }
|
|
|
- $post['actPrice'] = $currentPrice;
|
|
|
- $post['realPrice'] = $currentPrice;
|
|
|
- $order = OrderClass::addOrder($post);
|
|
|
- $orderId = $order['id'];
|
|
|
- $orderSn = $order['orderSn'];
|
|
|
+// $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
|
|
|
+// OrderClass::staffKdPay($payWay, $orderSn);
|
|
|
|
|
|
- foreach ($orderGoods as $key => $val) {
|
|
|
- $val['orderId'] = $orderId;
|
|
|
- $val['orderSn'] = $orderSn;
|
|
|
- OrderGoodsService::add($val);//创建订单商品列表
|
|
|
- }
|
|
|
- } else {
|
|
|
- //$orderType = 2 花材订单 组合开单
|
|
|
- $productData = $post['product'] ?? '';
|
|
|
- $product = json_decode($productData, true);
|
|
|
- if (empty($product)) {
|
|
|
- util::fail('请选择花材');
|
|
|
- }
|
|
|
- $currentPrice = $post['packingFee'] ?? 0; //包装费
|
|
|
- $orderProduct = [];
|
|
|
- $level = 1;
|
|
|
- $productInfo = ProductClass::formatProductInfo($product, $level);
|
|
|
- $currentPrice = bcadd($currentPrice, $productInfo['price'], 2);
|
|
|
- $sendCost = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
|
|
|
- $post['sendCost'] = $sendCost;
|
|
|
- $currentPrice = bcadd($currentPrice, $sendCost, 2);
|
|
|
- $post['prePrice'] = $currentPrice;
|
|
|
-
|
|
|
- if (isset($post['modifyPrice'])) {
|
|
|
- //商家打折,修改金额
|
|
|
- $modifyPrice = $post['modifyPrice'] ?? 0;
|
|
|
- if ($modifyPrice > $currentPrice) {
|
|
|
- util::fail('实收金额大于订单总金额');
|
|
|
- }
|
|
|
- if ($modifyPrice < $currentPrice) {
|
|
|
- $post['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
|
|
|
- $post['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
- $currentPrice = $modifyPrice;
|
|
|
- }
|
|
|
- }
|
|
|
- $post['actPrice'] = $currentPrice;
|
|
|
- $post['realPrice'] = $currentPrice;
|
|
|
-
|
|
|
- foreach ($product as $key => $val) {
|
|
|
- $productId = $val['productId'];
|
|
|
- $bigNum = $val['bigNum'];
|
|
|
- $smallNum = $val['smallNum'];
|
|
|
- $orderProduct[] = [
|
|
|
- 'productId' => $productId,
|
|
|
- 'bigNum' => $bigNum,
|
|
|
- 'smallNum' => $smallNum,
|
|
|
- ];
|
|
|
- //减库存
|
|
|
- ProductClass::decreaseStock($productId, $bigNum, $smallNum, true);
|
|
|
- }
|
|
|
-
|
|
|
- $order = OrderClass::addOrder($post);
|
|
|
- $orderId = $order['id'];
|
|
|
- $orderSn = $order['orderSn'];
|
|
|
-
|
|
|
- foreach ($orderProduct as $key => $val) {
|
|
|
- $val['orderSn'] = $orderSn;
|
|
|
- OrderItemClass::add($val);
|
|
|
- }
|
|
|
- }
|
|
|
- $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
|
|
|
- OrderClass::staffKdPay($payWay, $orderSn);
|
|
|
+// util::success(['orderSn' => $orderSn, 'totalPrice' => $currentPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
|
|
|
|
|
|
- util::success(['orderSn' => $orderSn, 'totalPrice' => $currentPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
|
|
|
}
|
|
|
|
|
|
//下单要用到的相关信息 ssh 2019.12.6
|