| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace bizHd\purchase\classes;
- use bizHd\cg\classes\AcceptClass;
- use bizHd\merchant\classes\ShopClass;
- use bizHd\product\classes\ProductClass;
- use common\components\dict;
- use common\components\orderSn;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- use bizGhs\stock\classes\StockRecordClass;
- class PurchaseItemClass extends BaseClass
- {
- public static $baseFile = '\bizHd\purchase\models\PurchaseItem';
- public static function acceptItem($cgId, $ptItemId, $num)
- {
- $cg = PurchaseClass::getById($cgId, true);
- if (empty($cg)) {
- util::fail('没有采购信息');
- }
- $cgOrderSn = $cg->orderSn ?? '';
- $shopId = $cg->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('没有找到采购门店信息');
- }
- $pfShopId = $shop->pfShopId ?? 0;
- if (!empty($pfShopId)) {
- util::fail('客户有批发店,不能直接赠送');
- }
- $sjId = $cg->sjId ?? 0;
- $mainId = $cg->mainId ?? 0;
- $targetId = $cg->id ?? 0;
- $cgItemList = PurchaseItemClass::getAllByCondition(['orderSn' => $cgOrderSn], null, '*', null, true);
- if (empty($cgItemList)) {
- util::fail('没有采购信息哦');
- }
- $targetSonId = 0;
- $productId = 0;
- $selectInfo = null;
- foreach ($cgItemList as $cgItem) {
- $currentPtItemId = $cgItem->itemId ?? 0;
- $currentId = $cgItem->id ?? 0;
- if ($currentPtItemId == $ptItemId) {
- $targetSonId = $currentId;
- $productId = $cgItem->productId ?? 0;
- $selectInfo = $cgItem;
- }
- }
- if (empty($selectInfo)) {
- util::fail('没有采购信息');
- }
- $selectInfo->acceptNum = bcadd($selectInfo->acceptNum, $num);
- $selectInfo->save();
- if (empty($productId)) {
- util::fail('没有找到采购的花材信息');
- }
- $product = ProductClass::getById($productId, true);
- if (empty($product)) {
- util::fail('没有花材信息');
- }
- $orderSn = orderSn::getAcceptSn();
- $accData = [
- 'orderSn' => $orderSn,
- 'mainId' => $mainId,
- 'productId' => $productId,
- 'name' => $product->name ?? '',
- 'cover' => $product->cover ?? '',
- 'ratio' => $product->ratio ?? 20,
- 'ratioType' => $product->ratioType ?? 0,
- 'ptItemId' => $ptItemId,
- 'giveNum' => $num,
- 'targetId' => $targetId,
- 'targetSonId' => $targetSonId,
- 'customId' => $cg->customId ?? 0,
- 'ghsId' => $cg->ghsId ?? 0,
- 'ghsName' => $cg->ghsName ?? '',
- 'ghsAvatar' => $cg->ghsAvatar ?? '',
- 'ghsMobile' => $cg->ghsMobile ?? '',
- ];
- $ac = AcceptClass::add($accData, true);
- $stockInfo = \bizGhs\product\classes\ProductClass::addStock($productId, $num, 0);
- $oldStock = $stockInfo['oldStock'];
- $newStock = $stockInfo['newStock'];
- $stockItem = [[
- 'productId' => $productId,
- 'itemId' => $ptItemId,
- 'itemNum' => $num,
- 'oldStock' => $oldStock,
- 'itemStock' => $oldStock,
- 'newStock' => $newStock,
- 'bigNum' => $num,
- 'smallNum' => 0,
- ]];
- $stockData = [];
- $stockData['shopId'] = $shopId;
- $stockData['relateName'] = '';
- $stockData['ptStyle'] = dict::getDict('ptStyle', 'hd');
- $stockData['orderSn'] = $orderSn;
- $stockData['sjId'] = $sjId;
- $stockData['itemInfo'] = $stockItem;
- $stockData['relateName'] = $cg->ghsName;
- StockRecordClass::addRecordByOrder($stockData, StockRecordClass::STOCK_RECORD_TYPE_ACCEPT);
- return $ac;
- }
- public static function getOrderItemDetail($orderSn)
- {
- return self::getAllByCondition(['orderSn' => $orderSn], 'id ASC', '*');
- }
- }
|