|
|
@@ -4,6 +4,7 @@ namespace hd\controllers;
|
|
|
|
|
|
use biz\admin\classes\AdminClass;
|
|
|
use biz\ghs\classes\GhsClass;
|
|
|
+use bizGhs\custom\classes\CustomClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
use bizHd\purchase\services\PurchaseService;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
@@ -22,34 +23,45 @@ class PurchaseController extends BaseController
|
|
|
$post = Yii::$app->request->post();
|
|
|
$ghsId = $post['ghsId'] ?? 0;
|
|
|
//供货商
|
|
|
- $supplier = GhsClass::getById($ghsId);
|
|
|
- if (empty($supplier)) {
|
|
|
+ $ghsInfo = GhsClass::getById($ghsId);
|
|
|
+ if (empty($ghsInfo)) {
|
|
|
util::fail('没有找到供货商');
|
|
|
}
|
|
|
- $currentShopId = $supplier['shopId'] ?? 0;
|
|
|
- $post['merchantId'] = $this->sjId;
|
|
|
- $post['shopId'] = $this->shopId;
|
|
|
- $post['shopAdminId'] = $this->shopAdminId;
|
|
|
- $shopAdmin = $this->shopAdmin;
|
|
|
- $name = $shopAdmin['name'] ?? '';
|
|
|
- $post['shopAdminName'] = $name;
|
|
|
- $product = $post['product'] ?? '';
|
|
|
- $productList = json_decode($product, true);
|
|
|
- //判断product数据是不是同个供货商的
|
|
|
- ProductClass::valid($productList, $currentShopId);
|
|
|
- $post['product'] = $productList;
|
|
|
- $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
|
|
|
- $respond = PurchaseService::addPurchase($post);
|
|
|
- $orderSn = $respond['orderSn'] ?? '';
|
|
|
- $actPrice = $respond['actPrice'] ?? '';
|
|
|
- $data = [
|
|
|
- 'orderSn' => $orderSn,
|
|
|
- 'actPrice' => $actPrice,
|
|
|
- 'hasBalancePay' => 1,
|
|
|
- 'hasPayPassword' => 0,
|
|
|
- 'hasDebtPay' => 1,
|
|
|
- ];
|
|
|
- util::success($data);
|
|
|
+ $connection = Yii::$app->db;//事务处理
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ $currentShopId = $ghsInfo['shopId'] ?? 0;
|
|
|
+ $post['merchantId'] = $this->sjId;
|
|
|
+ $post['shopId'] = $this->shopId;
|
|
|
+ $post['shopAdminId'] = $this->shopAdminId;
|
|
|
+ $post['ghsId'] = $ghsId;
|
|
|
+ $customId = $ghsInfo['customId'] ?? 0;
|
|
|
+ $post['customId'] = $customId;
|
|
|
+ $shopAdmin = $this->shopAdmin;
|
|
|
+ $name = $shopAdmin['name'] ?? '';
|
|
|
+ $post['shopAdminName'] = $name;
|
|
|
+ $product = $post['product'] ?? '';
|
|
|
+ $productList = json_decode($product, true);
|
|
|
+ //判断product数据是不是同个供货商的
|
|
|
+ ProductClass::valid($productList, $currentShopId);
|
|
|
+ $post['product'] = $productList;
|
|
|
+ $post['sendCost'] = isset($post['sendCost']) && is_numeric($post['sendCost']) ? $post['sendCost'] : 0;
|
|
|
+ $respond = PurchaseService::createPurchase($post);
|
|
|
+ $orderSn = $respond['orderSn'] ?? '';
|
|
|
+ $actPrice = $respond['actPrice'] ?? '';
|
|
|
+ $transaction->commit();
|
|
|
+ $data = [
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'actPrice' => $actPrice,
|
|
|
+ 'hasBalancePay' => 1,
|
|
|
+ 'hasPayPassword' => 0,
|
|
|
+ 'hasDebtPay' => 1,
|
|
|
+ ];
|
|
|
+ util::success($data);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ util::fail();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//延期支付 ssh 2021.1.24
|
|
|
@@ -59,6 +71,21 @@ class PurchaseController extends BaseController
|
|
|
$orderSn = $get['orderSn'] ?? 0;
|
|
|
$info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
|
|
|
PurchaseClass::valid($info->attributes, $this->shopId);
|
|
|
+ $deadline = $info->deadline;
|
|
|
+ if ($deadline <= date("Y-m-d H:i:s")) {
|
|
|
+ PurchaseClass::cancel($info);
|
|
|
+ util::fail('订单已失效,请重新采购');
|
|
|
+ }
|
|
|
+ $ghsId = $info->ghsId;
|
|
|
+ $ghs = GhsClass::getGhsInfo($ghsId);
|
|
|
+ $customId = $ghs['customId'] ?? 0;
|
|
|
+ $custom = CustomClass::getCustom($customId);
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('没有找到客户');
|
|
|
+ }
|
|
|
+ if (isset($custom['debt']) == false || $custom['debt'] == CustomClass::IS_DEBT_NO) {
|
|
|
+ util::fail('您没有延期付款权限');
|
|
|
+ }
|
|
|
$connection = Yii::$app->db;//事务处理
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|