| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/3/2 14:34
- */
- namespace hd\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\item\classes\PtItemClass;
- use bizGhs\item\classes\ItemClassClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\product\services\ProductService;
- use common\components\util;
- use Yii;
- class ProductController extends BaseController
- {
- public $guestAccess = ['ghs-item'];
- public function actionIndex()
- {
- $py = Yii::$app->request->get('py', '');
- //默认显示上架商品
- $status = Yii::$app->request->get('status', 1);
- //默认显示未删除商品
- $delStatus = Yii::$app->request->get('delStatus', 0);
- //获取所有当前供应商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- //中央ID
- $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
- $where['mainId'] = $this->mainId;
- if ($py) {
- $pyName = strtolower($py);
- $where['py'] = $pyName;
- }
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $where['delStatus'] = $delStatus;
- $level = 0;
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
- $data = ProductService::assembleData($classIds, $itemInfoData, true);
- util::success($data);
- }
- //当前门店所有花材分类
- public function actionList()
- {
- $classId = Yii::$app->request->get('classId', 0);
- $pyName = Yii::$app->request->get('py', '');
- $where['sjId'] = $this->sjId;
- if ($pyName) {
- $pyName = strtolower($pyName);
- $where['py'] = $pyName;
- }
- $shopId = Yii::$app->request->get('shopId', 0);
- if (!$shopId) {
- $shopId = $this->shopId;
- }
- $where['shopId'] = $shopId;
- if (!empty($classId)) {
- $where['classId'] = $classId;
- }
- $type = Yii::$app->request->get('type', '');
- $showPage = Yii::$app->request->get('showPage', 0);
- //需要显示分页
- if ($showPage) {
- $respond = ProductClass::getList("*", $where, "inTurn desc");
- $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
- $respond['list'] = ProductClass::groupProductInfo($respond['list']);
- util::success($respond);
- }
- $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
- $data = ProductClass::groupProductInfo($data);
- if ($type == 'waring') {
- //库存预警
- $newData = [];
- foreach ($data as $v) {
- if ($v['stock'] <= $v['stockWarning']) {
- $newData[] = $v;
- }
- }
- util::success(['list' => $newData]);
- }
- util::success(['list' => $data]);
- }
- //从零售端采购入库,查看供应商的某个门店的product
- public function actionGhsItem()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $ghs = GhsClass::getGhsInfo($id);
- if (empty($ghs)) {
- util::fail('没有找到供应商');
- }
- $sjId = $ghs['sjId'] ?? 0;
- $shopId = $ghs['shopId'] ?? 0;
- $black = $ghs['black'] ?? 2;
- if ($black == 2) {
- util::fail('您已被列入黑名单');
- }
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
- //获取所有当前供应商的分类 (全部、常用)
- //根据分类组装分类下的花材信息
- //中央ID
- $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
- // $where['sjId'] = $sjId;
- // $where['shopId'] = $shopId;
- $where['mainId'] = $this->mainId;
- $where['delStatus'] = 0;
- $where['status'] = 1;
- $level = $ghs['giveLevel'] ?? 0;
- $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
- $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
- $data = ProductService::assembleData($classIds, $itemInfoData, true);
- util::success($data);
- } catch (\Exception $e) {
- $transaction->rollBack();
- util::fail();
- }
- }
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $respond = ProductClass::getItemInfo($id);
- $ptItemId = $respond['itemId'] ?? 0;
- $ptItemInfo = PtItemClass::getById($ptItemId);
- $respond['ptItemInfo'] = $ptItemInfo;
- util::success($respond);
- }
- public function actionUpdate()
- {
- $post = Yii::$app->request->post();
- ProductClass::updateProduct($post);
- util::complete();
- }
- //批量修改product 排序,成本价,加价
- public function actionBatchUpdate()
- {
- //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
- $data = Yii::$app->request->post('data', '');
- $type = Yii::$app->request->post('type', '');
- if (empty($data) || empty($type)) {
- util::fail("参数错误");
- }
- if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
- $data = json_decode($data, true);
- foreach ($data as $v) {
- $id = $v['id'];
- $val = $v[$type] ?? '';
- $where = [];
- $where['id'] = $id;
- $where['shopId'] = $this->shopId;
- $where['sjId'] = $this->sjId;
- if (empty($val)) {
- util::fail("参数错误1");
- }
- $data = [
- $type => $val
- ];
- ProductClass::updateByCondition($where, $data);
- ProductClass::autoPriceById($id);
- }
- util::complete();
- }
- //供应商产品的详情 shish 20210903
- public function actionGhsProductDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $ghsId = Yii::$app->request->get('ghsId', 0);
- $ghs = GhsClass::getById($ghsId, true);
- GhsClass::valid($ghs, $this->shopId);
- $shopId = $ghs->shopId ?? 0;
- $product = ProductClass::getItemInfo($id, $ghs);
- if (isset($product['shopId']) == false || $product['shopId'] != $shopId) {
- util::fail('没有权限访问');
- }
- $original = ProductClass::getById($id);
- if (isset($original['discountPrice']) && $original['discountPrice'] > 0) {
- $discountPrice = $original['discountPrice'];
- $original['price'] = floatval($discountPrice);
- $skAddPrice = $original['skAddPrice'] ?? 0;
- $addPrice = $original['addPrice'] ?? 0;
- $hjAddPrice = $original['hjAddPrice'] ?? 0;
- $zsAddPrice = $original['zsAddPrice'] ?? 0;
- $sk = bcsub($addPrice, $skAddPrice, 2);
- $hj = bcsub($addPrice, $hjAddPrice, 2);
- $zs = bcsub($addPrice, $zsAddPrice, 2);
- $original['skPrice'] = floatval(bcsub($discountPrice, $sk, 2));
- $original['hjPrice'] = floatval(bcsub($discountPrice, $hj, 2));
- $original['zsPrice'] = floatval(bcsub($discountPrice, $zs, 2));
- }
- $product['originalInfo'] = $original;
- util::success($product);
- }
- }
|