| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace ghs\controllers;
- use biz\item\classes\PtItemClass;
- use bizGhs\item\classes\ItemClass;
- use bizGhs\item\services\ItemService;
- use common\components\util;
- use bizGhs\product\classes\ProductClass;
- use Yii;
- class ItemController extends BaseController
- {
- //列出所有花材,包括特价花材列表 ssh 20220315
- public function actionShowList()
- {
- $where['mainId'] = $this->mainId;
- $where['delStatus'] = 0;
- $list = ItemClass::getShowList($where);
- util::success(['list' => $list]);
- }
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $post['adminId'] = $this->adminId;
- $post['sjId'] = $this->sjId;
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
- ItemService::addGhsItem($post);
- $transaction->commit();
- util::complete('添加成功');
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail('添加失败');
- }
- }
- //批量添加花材
- public function actionBatchAdd()
- {
- $shopAdmin = $this->shopAdmin;
- if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
- util::fail('超管才能操作');
- }
- $post = Yii::$app->request->post();
- //[{itemId:1000,classId:2,price:1,stockWarning:1}]
- $data = $post['data'];
- if (empty($data)) {
- util::fail("请选花材");
- }
- $data = json_decode($data, true);
- if (!is_array($data) || empty($data)) {
- util::fail("请选花材");
- }
- $sjId = $this->sjId;
- $ids = array_column($data,'itemId');
- $ids = array_unique(array_filter($ids));
- $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId'=>['in',$ids]]);
- if(!empty($has)){
- util::fail("有花材已经添加过了");
- }
- $connection = Yii::$app->db;//事务处理
- $transaction = $connection->beginTransaction();
- try {
- foreach ($data as $v) {
- $v['adminId'] = $this->adminId;
- $v['sjId'] = $sjId;
- ItemService::addGhsItem($v);
- }
- $transaction->commit();
- util::complete('添加成功');
- } catch (Exception $e) {
- $transaction->rollBack();
- util::fail();
- }
- }
- public function actionDelete()
- {
- util::fail('不能删除哦!');
- }
- //获取平台里的花材信息
- public function actionPlatformItem()
- {
- $py = Yii::$app->request->get('py', '');
- $where = [];
- if ($py) {
- $where = ['py' => $py];
- }
- $list = PtItemClass::getItemList($where);
- util::success($list);
- }
- }
|