|
|
@@ -15,17 +15,65 @@ class StockOutController extends BaseController
|
|
|
//全部出库 ssh 20220906
|
|
|
public function actionAllOut()
|
|
|
{
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $inShopId = $get['shopId'] ?? 0;
|
|
|
+ $inShop = ShopClass::getById($inShopId, true);
|
|
|
+ if (empty($inShop)) {
|
|
|
+ util::fail('入库门店没有找到');
|
|
|
+ }
|
|
|
+ $inMainId = $inShop->mainId ?? 0;
|
|
|
$shop = $this->shop;
|
|
|
if ($shop->default == 1) {
|
|
|
util::fail('首店库存不能全部出库');
|
|
|
}
|
|
|
|
|
|
- util::fail('开发中');
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
|
|
|
- //$mainId = $this->mainId;
|
|
|
- //$list = ProductClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
|
|
|
+ try {
|
|
|
|
|
|
- util::complete();
|
|
|
+ $shopId = $this->shopId;
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $sjId = $shop->sjId ?? 0;
|
|
|
+ $list = ProductClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
|
|
|
+ if (empty($list)) {
|
|
|
+ util::fail('没有花材');
|
|
|
+ }
|
|
|
+ $itemInfo = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ if ($item->delStatus == 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $stock = $item->stock ?? 0;
|
|
|
+ $ratio = $item->ratio ?? 0;
|
|
|
+ if ($stock <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $bigNum = intval($stock);
|
|
|
+ $small = bcsub($stock, $bigNum, 2);
|
|
|
+ $smallNum = bcmul($small, $ratio);
|
|
|
+ $currentId = $item->id;
|
|
|
+ $itemInfo[] = ['productId' => $currentId, 'bigNum' => $bigNum, 'smallNum' => $smallNum];
|
|
|
+ }
|
|
|
+ if (empty($itemInfo)) {
|
|
|
+ util::fail('没有库存');
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'remark' => '全部出库',
|
|
|
+ 'itemInfo' => $itemInfo,
|
|
|
+ 'inShopId' => $inShopId,
|
|
|
+ 'inMainId' => $inMainId,
|
|
|
+ 'outMainId' => $mainId,
|
|
|
+ 'outShopId' => $shopId,
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ ];
|
|
|
+ StockOutOrderClass::addOrder($data);
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete();
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ util::fail('出库失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//出库列表 lqh 2021.1.23
|