|
|
@@ -693,22 +693,70 @@ class ProductController extends BaseController
|
|
|
|
|
|
public function actionUpdate()
|
|
|
{
|
|
|
- $shop = $this->shop ?? [];
|
|
|
- $pfShopId = $shop->pfShopId ?? 0;
|
|
|
- if (!empty($pfShopId)) {
|
|
|
- util::fail('请在批发端操作');
|
|
|
- }
|
|
|
-
|
|
|
- $post = Yii::$app->request->post();
|
|
|
$shopAdmin = $this->shopAdmin;
|
|
|
if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
|
|
|
- util::fail('超管才能修改');
|
|
|
+ util::fail('超管才能操作');
|
|
|
+ }
|
|
|
+
|
|
|
+ $shop = $this->shop;
|
|
|
+ $join = $shop->join ?? 0;
|
|
|
+ $default = $shop->default ?? 0;
|
|
|
+ if ($join == 0 && $default == 0) {
|
|
|
+ //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
|
|
|
+ if ($shopAdmin->super != 1) {
|
|
|
+ util::fail('请先开通超管权限');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ $deadline = $shop->deadline;
|
|
|
+ $deadTime = strtotime($deadline);
|
|
|
+ if (time() > $deadTime) {
|
|
|
+ util::fail('系统已到期');
|
|
|
+ }
|
|
|
+
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $discountPrice = $post['discountPrice'] ?? 0;
|
|
|
+ if ($discountPrice > 0) {
|
|
|
+ if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
|
|
|
+ $addPrice = $post['addPrice'] ?? 0;
|
|
|
+ $hjAddPrice = $post['hjAddPrice'] ?? 0;
|
|
|
+ $skMore = $post['skMore'] ?? 0;
|
|
|
+ $diff = bcsub($addPrice, $hjAddPrice, 2);
|
|
|
+ if ($diff > 0 && $discountPrice > $diff) {
|
|
|
+ $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
|
|
|
+ } else {
|
|
|
+ $hjDiscountPrice = $discountPrice;
|
|
|
+ }
|
|
|
+ $diff = bcsub($skMore, $addPrice, 2);
|
|
|
+ if ($diff > 0) {
|
|
|
+ $skDiscountPrice = bcadd($diff, $discountPrice, 2);
|
|
|
+ } else {
|
|
|
+ $skDiscountPrice = $discountPrice;
|
|
|
+ }
|
|
|
+ $post['skDiscountPrice'] = $skDiscountPrice;
|
|
|
+ $post['hjDiscountPrice'] = $hjDiscountPrice;
|
|
|
+ }
|
|
|
+ $reachNum = $post['reachNum'] ?? 0;
|
|
|
+ $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
|
|
|
+ if ($reachNum > 0 && $reachNumDiscount > 0) {
|
|
|
+ util::fail('特价和满减不能同时进行');
|
|
|
+ }
|
|
|
+ }
|
|
|
$post['adminId'] = $this->adminId;
|
|
|
+ $post['staffId'] = $this->shopAdmin->id;
|
|
|
$post['staffName'] = $this->shopAdmin->name;
|
|
|
- ItemClass::updateProduct($post, $this->shop);
|
|
|
- util::complete();
|
|
|
+
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ ProductClass::updateProduct($post, $this->shop);
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Yii::info("操作失败:" . $e->getMessage());
|
|
|
+ $transaction->rollBack();
|
|
|
+ util::fail('操作失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//批量修改product 排序,成本价,加价
|