|
|
@@ -3,11 +3,18 @@
|
|
|
namespace bizMall\order\services;
|
|
|
|
|
|
use bizMall\base\services\BaseService;
|
|
|
+use bizMall\custom\classes\CustomClass;
|
|
|
+use bizMall\goods\classes\GoodsClass;
|
|
|
+use bizMall\item\classes\ItemClass;
|
|
|
use bizMall\merchant\services\MerchantCapitalService;
|
|
|
use bizMall\merchant\services\MerchantService;
|
|
|
use bizMall\order\classes\OrderClass;
|
|
|
+use bizMall\order\classes\OrderGoodsClass;
|
|
|
+use bizMall\order\classes\OrderItemClass;
|
|
|
use bizMall\promote\services\CouponService;
|
|
|
use bizMall\user\classes\UserAssetClass;
|
|
|
+use common\components\dict;
|
|
|
+use common\components\orderSn;
|
|
|
use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
@@ -17,9 +24,159 @@ class OrderService extends BaseService
|
|
|
|
|
|
public static $baseFile = '\bizMall\order\classes\OrderClass';
|
|
|
|
|
|
- public static function payAfter($order, $payWay)
|
|
|
+ public static function createOrder($data)
|
|
|
{
|
|
|
-
|
|
|
+ $orderSn = orderSn::getOrderSn();
|
|
|
+ $sjId = $data['sjId'] ?? 0;
|
|
|
+ $shopId = $data['shopId'] ?? 0;
|
|
|
+ $userId = $data['userId'] ?? 0;
|
|
|
+ $mainId = $data['mainId'] ?? 0;
|
|
|
+ $custom = [];
|
|
|
+ $customId = 0;
|
|
|
+ $hdId = 0;
|
|
|
+ if (!empty($userId) && !empty($shopId)) {
|
|
|
+ $custom = CustomClass::getByCondition(['shopId' => $shopId, 'userId' => $userId], true);
|
|
|
+ $customId = $custom->id ?? 0;
|
|
|
+ }
|
|
|
+ $product = $data['product'] ?? [];
|
|
|
+ if (empty($product)) {
|
|
|
+ util::fail('没有花材');
|
|
|
+ }
|
|
|
+ $gIds = [];
|
|
|
+ $itIds = [];
|
|
|
+ foreach ($product as $key => $val) {
|
|
|
+ $currentId = $val['productId'] ?? 0;
|
|
|
+ $property = $val['property'];
|
|
|
+ if ($property == dict::getDict('property', 'goods')) {
|
|
|
+ $gIds[] = $currentId;
|
|
|
+ }
|
|
|
+ if ($property == dict::getDict('property', 'item')) {
|
|
|
+ $itIds[] = $currentId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $goodsInfo = [];
|
|
|
+ $gIds = array_unique(array_filter($gIds));
|
|
|
+ if (!empty($gIds)) {
|
|
|
+ $goodsInfo = GoodsClass::getByIds($gIds, null, 'id');
|
|
|
+ }
|
|
|
+ $itemInfo = [];
|
|
|
+ $itIds = array_unique(array_filter($itIds));
|
|
|
+ if (!empty($itIds)) {
|
|
|
+ $itemInfo = ItemClass::getByIds($itIds, null, 'id');
|
|
|
+ }
|
|
|
+ $goodsPrice = 0;
|
|
|
+ foreach ($product as $key => $val) {
|
|
|
+ if (isset($val['property']) == false) {
|
|
|
+ util::fail('没有找到产品属性');
|
|
|
+ }
|
|
|
+ $currentPrice = $val['price'] ?? 0;
|
|
|
+ $goodsPrice = bcadd($goodsPrice, $currentPrice, 2);
|
|
|
+ $property = $val['property'];
|
|
|
+ $unitPrice = $val['unitPrice'] ?? 0;
|
|
|
+ $unitType = $val['unitType'] ?? 0;
|
|
|
+ $currentId = $val['productId'] ?? 0;
|
|
|
+ $num = $val['num'] ?? 0;
|
|
|
+ if ($property == dict::getDict('property', 'goods')) {
|
|
|
+ $name = $goodsInfo[$currentId]['name'] ?? '';
|
|
|
+ $cover = $goodsInfo[$currentId]['cover'] ?? '';
|
|
|
+ if (!empty($groupCover)) {
|
|
|
+ $groupCover = $cover;
|
|
|
+ }
|
|
|
+ $currentMainId = $goodsInfo[$currentId]['mainId'] ?? 0;
|
|
|
+ if ($currentMainId != $mainId) {
|
|
|
+ util::fail('不是您的商品');
|
|
|
+ }
|
|
|
+ $currentGoodsData = [
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'goodsId' => $currentId,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'hdId' => $hdId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'name' => $name,
|
|
|
+ 'cover' => $cover,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'num' => $num,
|
|
|
+ 'price' => bcmul($unitPrice, $num, 2),
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ ];
|
|
|
+ //库存变化在这里
|
|
|
+ OrderGoodsClass::addData($currentGoodsData, $custom);
|
|
|
+ }
|
|
|
+ if ($property == dict::getDict('property', 'item')) {
|
|
|
+ $name = $itemInfo[$currentId]['name'] ?? '';
|
|
|
+ $cover = $itemInfo[$currentId]['cover'] ?? '';
|
|
|
+ if (!empty($groupCover)) {
|
|
|
+ $groupCover = $cover;
|
|
|
+ }
|
|
|
+ $ratio = $itemInfo[$currentId]['ratio'] ?? 20;
|
|
|
+ $currentMainId = $itemInfo[$currentId]['mainId'] ?? 0;
|
|
|
+ if ($currentMainId != $mainId) {
|
|
|
+ util::fail('不是您的花材' . $mainId . ' ' . $currentMainId);
|
|
|
+ }
|
|
|
+ if ($unitType == dict::getDict('unitType', 'big')) {
|
|
|
+ $unitName = $itemInfo[$currentId]['bigUnit'] ?? '';
|
|
|
+ $unitId = $itemInfo[$currentId]['bigUnitId'] ?? 0;
|
|
|
+ $totalNum = $num;
|
|
|
+ } else {
|
|
|
+ $unitName = $itemInfo[$currentId]['smallUnit'] ?? '';
|
|
|
+ $unitId = $itemInfo[$currentId]['smallUnitId'] ?? 0;
|
|
|
+ $totalNum = bcdiv($num, $ratio, 2);
|
|
|
+ }
|
|
|
+ $ptItemId = $itemInfo[$currentId]['itemId'] ?? 0;
|
|
|
+ $currentItemData = [
|
|
|
+ 'name' => $name,
|
|
|
+ 'cover' => $cover,
|
|
|
+ 'ratio' => $ratio,
|
|
|
+ 'unitType' => $unitType,
|
|
|
+ 'unitName' => $unitName,
|
|
|
+ 'unitId' => $unitId,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'num' => $num,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'itemId' => $currentId,
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
+ 'totalNum' => $totalNum,
|
|
|
+ 'totalPrice' => 0,
|
|
|
+ 'customId' => $customId,
|
|
|
+ 'hdId' => $hdId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'price' => bcmul($unitPrice, $num, 2)
|
|
|
+ ];
|
|
|
+ //库存变化在这里
|
|
|
+ OrderItemClass::addData($currentItemData, $custom);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sendCost = $data['sendCost'] ?? 0;
|
|
|
+ $totalPrice = bcadd($goodsPrice, $sendCost, 2);
|
|
|
+ $modifyPrice = $data['modifyPrice'] ?? 0;
|
|
|
+ if ($modifyPrice > $totalPrice) {
|
|
|
+ //人工资材包装费
|
|
|
+ $data['labourCost'] = bcsub($modifyPrice, $totalPrice, 2);
|
|
|
+ }
|
|
|
+ if ($modifyPrice < $totalPrice) {
|
|
|
+ //优惠
|
|
|
+ $data['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
+ $discountAmount = bcsub($totalPrice, $modifyPrice, 2);
|
|
|
+ $data['discountAmount'] = $discountAmount;
|
|
|
+ }
|
|
|
+ $data['goodsPrice'] = $goodsPrice;
|
|
|
+ $data['prePrice'] = $totalPrice;
|
|
|
+ $data['orderPrice'] = $modifyPrice;
|
|
|
+ $data['actPrice'] = $modifyPrice;
|
|
|
+ $data['realPrice'] = $modifyPrice;
|
|
|
+ $data['customId'] = $customId;
|
|
|
+ $data['hdId'] = $hdId;
|
|
|
+ $data['sjId'] = $sjId;
|
|
|
+ $data['shopId'] = $shopId;
|
|
|
+ $data['mainId'] = $mainId;
|
|
|
+ $data['payWay'] = dict::getDict('payWay', 'unPay');
|
|
|
+ $data['orderSn'] = $orderSn;
|
|
|
+ $data['status'] = OrderClass::ORDER_STATUS_UN_PAY;
|
|
|
+ $returnOrder = OrderClass::addOrder($data);
|
|
|
+ return $returnOrder;
|
|
|
}
|
|
|
|
|
|
//获取订单信息 ssh 2019.11.28
|