|
|
@@ -8,6 +8,7 @@ use biz\merchant\services\MerchantExtendService;
|
|
|
use biz\merchant\services\MerchantService;
|
|
|
use bizGhs\merchant\services\ShopService;
|
|
|
use biz\order\classes\OrderSendClass;
|
|
|
+use bizGhs\order\classes\OrderClass;
|
|
|
use bizGhs\order\services\OrderService;
|
|
|
use biz\saas\services\RegionService;
|
|
|
use biz\user\services\UserService;
|
|
|
@@ -26,95 +27,40 @@ class OrderController extends BaseController
|
|
|
//商城下单操作 shish 2021.1.14
|
|
|
public function actionCreateOrder()
|
|
|
{
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
|
|
|
- $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
|
|
|
- $needSend = $post['needSend'] ?? 1;
|
|
|
-// if (empty($goodsId)) {
|
|
|
-// util::fail('请选择商品');
|
|
|
-// }
|
|
|
-// $goodsInfo = GoodsService::getGoodsInfo($goodsId);
|
|
|
-// if (empty($goodsInfo)) {
|
|
|
-// util::fail('没有找到商品');
|
|
|
-// }
|
|
|
-// if (isset($goodsInfo['stock']) == false || $goodsInfo['stock'] == 0) {
|
|
|
-// util::fail('已经卖完了');
|
|
|
-// }
|
|
|
|
|
|
- //运费计算方式
|
|
|
- $freightType = $goodsInfo['freightType'] ?? 0;
|
|
|
+ //供货商端口:员工开单、客户开单
|
|
|
|
|
|
- //$post['adminId'] = $this->adminId;
|
|
|
- $post['adminId'] = 0;
|
|
|
- $user = $this->admin;
|
|
|
- $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
|
|
|
- $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 = Yii::$app->request->post();
|
|
|
+ $post['adminId'] = 0;
|
|
|
$post['payWay'] = $this->isWx == true ? 0 : 1;
|
|
|
- $defaultShopId = MerchantService::getDefaultShopId($this->ghs);
|
|
|
- if (empty($defaultShopId)) {
|
|
|
- util::fail('没有找到门店');
|
|
|
- }
|
|
|
- //计算运费
|
|
|
- $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
|
|
|
- $sendCost = 0;
|
|
|
- //按距离计算运费并且客户要求送的
|
|
|
- if ($freightType == 0 && $needSend == 1) {
|
|
|
- $lat = $post['latitude'];//收货人纬度
|
|
|
- $lng = $post['longitude'];//收货人经度
|
|
|
- $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->ghsExtend);
|
|
|
- $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
|
|
|
- }
|
|
|
- $post['sendCost'] = $sendCost;
|
|
|
- $post['merchantId'] = $this->ghsId;
|
|
|
- $post['shopId'] = $defaultShopId;
|
|
|
-
|
|
|
- //计算总金额
|
|
|
- //$unitPrice = $goodsInfo['price'];
|
|
|
- $unitPrice = 1;
|
|
|
-
|
|
|
- $goodsPrice = $unitPrice * $goodsNum;
|
|
|
- $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
|
|
|
- //非门店订单
|
|
|
- $store = 0;
|
|
|
- $post['store'] = $store;
|
|
|
- //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
|
|
|
- $sourceType = $this->isWx ? 0 : 1;
|
|
|
- if (httpUtil::isMiniProgram()) {
|
|
|
- $sourceType = 2;
|
|
|
- }
|
|
|
- $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
|
|
|
- $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
|
|
|
- $actPrice = $discountData['price'];
|
|
|
- $post['discountType'] = $discountData['discountType'];
|
|
|
- $post['discountAmount'] = $discountData['discountAmount'];
|
|
|
-
|
|
|
+ $post['ghsId'] = $this->ghsId;
|
|
|
+ $post['shopId'] = 0;
|
|
|
$now = time();
|
|
|
$expireTime = $now + 1800;//订单30分钟后过期
|
|
|
$post['deadline'] = $expireTime;
|
|
|
$post['fromType'] = 1;//商城
|
|
|
$post['prePrice'] = $prePrice;
|
|
|
$post['actPrice'] = $actPrice;
|
|
|
- $order = OrderService::addOrder($post);
|
|
|
+ $order = OrderClass::addOrder($post);
|
|
|
$orderId = $order['id'];
|
|
|
$orderSn = $order['orderSn'];
|
|
|
- $data = [
|
|
|
- 'orderId' => $orderId,
|
|
|
- 'goodsId' => $goodsId,
|
|
|
- 'userId' => $this->adminId,
|
|
|
- 'merchantId' => $this->ghsId,
|
|
|
- 'title' => '苏醒',
|
|
|
- 'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
|
|
|
- 'unitPrice' => $unitPrice,
|
|
|
- 'num' => $goodsNum,
|
|
|
- 'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
|
|
|
- 'goodsStyleId' => $goodsStyleId,
|
|
|
- 'createTime' => date("Y-m-d H:i:s"),
|
|
|
+ //花材商品
|
|
|
+ $itemData = [
|
|
|
+ [
|
|
|
+ 'orderId'=>$orderId,
|
|
|
+ 'itemId'=>0,
|
|
|
+ 'itemInfoId'=>0,
|
|
|
+ 'unitPrice'=>0.01,
|
|
|
+ 'unitNum'=>0,
|
|
|
+ 'num'=>0,
|
|
|
+ ],
|
|
|
];
|
|
|
//OrderGoodsService::add($data);//创建订单商品列表
|
|
|
- util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId]);
|
|
|
+ util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice]);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//下单要用到的相关信息 shish 2019.12.6
|