|
|
@@ -28,6 +28,71 @@ class PurchaseController extends BaseController
|
|
|
|
|
|
public $guestAccess = ['detail'];
|
|
|
|
|
|
+ //虚拟供货商的采购 ssh 20230308
|
|
|
+ public function actionAddVirtualCg()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $ghsId = $post['ghsId'] ?? 0;
|
|
|
+ $ghsInfo = GhsClass::getById($ghsId);
|
|
|
+ if (empty($ghsInfo)) {
|
|
|
+ util::fail('没有找到供货商');
|
|
|
+ }
|
|
|
+ if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
|
|
|
+ util::fail('这个是你自己的批发店');
|
|
|
+ }
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ $post['book'] = $post['book'] ?? 0;
|
|
|
+ $post['sjId'] = $this->sjId;
|
|
|
+ $post['shopId'] = $this->shopId;
|
|
|
+ $post['shopAdminId'] = $this->shopAdminId;
|
|
|
+ $post['ghsId'] = $ghsId;
|
|
|
+ $post['ghsName'] = $ghsInfo['name'] ?? '';
|
|
|
+ $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
|
|
|
+ $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
|
|
|
+ $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
|
|
|
+ $customId = $ghsInfo['customId'] ?? 0;
|
|
|
+ $post['customId'] = $customId;
|
|
|
+ $shopAdmin = $this->shopAdmin ?? null;
|
|
|
+ $name = $shopAdmin->name ?? '';
|
|
|
+ $post['shopAdminName'] = $name;
|
|
|
+ $post['mainId'] = $this->mainId;
|
|
|
+ $product = $post['product'] ?? '';
|
|
|
+ $productList = json_decode($product, true);
|
|
|
+ //判断product数据是不是同个供货商的
|
|
|
+ $ids = array_unique(array_filter(array_column($productList, 'productId')));
|
|
|
+ $productInfoList = ProductClass::getByIds($ids, null, 'id');
|
|
|
+ if (!empty($productInfoList)) {
|
|
|
+ foreach ($productInfoList as $currentInfo) {
|
|
|
+ if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
|
|
|
+ util::fail('只能选择同一家的商品哦');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($productInfoList) != count($ids)) {
|
|
|
+ util::fail('存在无效商品');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ util::fail('花材不存在');
|
|
|
+ }
|
|
|
+ //供货商预订单最低公斤数要求和每公斤服务费
|
|
|
+ $ghsInfo['kiloFee'] = 0;
|
|
|
+ $ghsInfo['miniKilo'] = 0;
|
|
|
+ $post['product'] = $productList;
|
|
|
+ $sendCost = 0;
|
|
|
+ $post['sendCost'] = $sendCost;
|
|
|
+ $packCost = 0;
|
|
|
+ $post['packCost'] = $packCost;
|
|
|
+ $respond = PurchaseService::createPurchase($post, $ghsInfo);
|
|
|
+ $transaction->commit();
|
|
|
+ util::success($respond);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ util::fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//生成采购单 ssh 2021.1.17
|
|
|
public function actionCreateOrder()
|
|
|
{
|
|
|
@@ -60,7 +125,7 @@ class PurchaseController extends BaseController
|
|
|
$ghsShopId = $ghsInfo['shopId'] ?? 0;
|
|
|
|
|
|
if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
|
|
|
- util::fail('这个是你的批发店');
|
|
|
+ util::fail('这个是你自己的批发店');
|
|
|
}
|
|
|
|
|
|
$connection = Yii::$app->db;//事务处理
|