| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace hd\controllers;
- use bizHd\product\classes\ProductClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\classes\PurchaseItemClass;
- use common\components\imgUtil;
- use Yii;
- use common\components\util;
- class CgItemController extends BaseController
- {
- //预存价格 ssh 20230725
- public function actionSaveCgPrice()
- {
- $post = Yii::$app->request->post();
- $data = $post['data'] ?? '';
- if (empty($data)) {
- util::fail('没有修改');
- }
- $arr = json_decode($data, true);
- if (empty($arr)) {
- util::fail('没有修改哦');
- }
- $cgId = $post['cgId'] ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- if (empty($cg)) {
- util::fail('没有找到采购单');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('没有权限');
- }
- $orderSn = $cg->orderSn ?? '';
- $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (empty($cgItemList)) {
- util::fail('没有找到花材');
- }
- $new = [];
- foreach ($arr as $product) {
- $currentId = $product['id'] ?? 0;
- $savePrice = $product['savePrice'] ?? 0;
- $saveSkPrice = $product['saveSkPrice'] ?? 0;
- $saveHjPrice = $product['saveHjPrice'] ?? 0;
- $new[$currentId]['savePrice'] = $savePrice;
- $new[$currentId]['saveSkPrice'] = $saveSkPrice;
- $new[$currentId]['saveHjPrice'] = $saveHjPrice;
- }
- foreach ($cgItemList as $cgItem) {
- $thisId = $cgItem->id ?? 0;
- if (isset($new[$thisId]) == false) {
- util::fail('有花材没有价格');
- }
- $info = $new[$thisId];
- $savePrice = $info['savePrice'] ?? 0;
- $saveSkPrice = $info['saveSkPrice'] ?? 0;
- $saveHjPrice = $info['saveHjPrice'] ?? 0;
- $cgItem->savePrice = $savePrice;
- $cgItem->saveSkPrice = $saveSkPrice;
- $cgItem->saveHjPrice = $saveHjPrice;
- $cgItem->save();
- }
- $cg->hasSavePrice = 1;
- $cg->save();
- util::complete();
- }
- //采购成功后改价时获取列表 ssh 2023311
- public function actionGetCgItemInfo()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cg = PurchaseClass::getById($id, true);
- if (empty($cg)) {
- util::fail('没有找到采购信息');
- }
- if ($cg->mainId != $this->mainId) {
- util::fail('无法操作');
- }
- $orderSn = $cg->orderSn ?? '';
- $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($list)) {
- $productIdList = array_column($list, 'productId');
- $itemList = ProductClass::getByIds($productIdList, null, 'id');
- foreach ($list as $key => $item) {
- $productId = $item['productId'] ?? 0;
- $cost = $item['xhUnitPrice'] ?? 0;
- $cost = round($cost);
- $current = $itemList[$productId] ?? [];
- $addPrice = $current['addPrice'] ?? 0;
- $hjAddPrice = $current['hjAddPrice'] ?? 0;
- $skMore = $current['skMore'] ?? 0;
- if (isset($item['savePrice']) && $item['savePrice'] > 0) {
- $suggestPrice = $item['savePrice'] ?? 0;
- $suggestSkPrice = $item['saveSkPrice'] ?? 0;
- $suggestHjPrice = $item['saveHjPrice'] ?? 0;
- } else {
- $suggestPrice = bcadd($cost, $addPrice, 2);
- $suggestSkPrice = bcadd($cost, $skMore, 2);
- $suggestHjPrice = bcadd($cost, $hjAddPrice, 2);
- }
- $suggestPrice = floatval($suggestPrice);
- $suggestSkPrice = floatval($suggestSkPrice);
- $suggestHjPrice = floatval($suggestHjPrice);
- $list[$key]['suggestPrice'] = $suggestPrice;
- $list[$key]['suggestSkPrice'] = $suggestSkPrice;
- $list[$key]['suggestHjPrice'] = $suggestHjPrice;
- $list[$key]['skMore'] = $skMore;
- $list[$key]['addPrice'] = $addPrice;
- $list[$key]['hjAddPrice'] = $hjAddPrice;
- //修改之前的批发价
- $beforeModifyPrice = $current['price'] ?? 0;
- $list[$key]['beforeModifyPrice'] = $beforeModifyPrice;
- }
- }
- $shop = $this->shop;
- $onlyCg = $shop->onlyCg ?? 1;
- util::success(['list' => $list, 'onlyCg' => $onlyCg]);
- }
- }
|