| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace ghs\controllers;
- use biz\cp\classes\PtCpClass;
- use bizGhs\cp\classes\CpClass;
- use bizGhs\cp\classes\CpClassClass;
- use bizGhs\cp\services\CpService;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use common\components\util;
- use Yii;
- class CpController extends BaseController
- {
- //采用平台花材 ssh 20240226
- public function actionAddPtCp()
- {
- util::fail('开发中');
- $get = Yii::$app->request->get();
- $ptCpId = $get['id'] ?? 0;
- $ptCp = PtCpClass::getById($ptCpId, true);
- if (empty($ptCp)) {
- util::fail('没有找到产品');
- }
- $cp = CpService::addPtCp($ptCp, $this->shop);
- util::success(['cp' => $cp]);
- }
- //根据分类id取集合,带分页 ssh 20231228
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $classId = $get['classId'] ?? 0;
- $search = $get['search'] ?? '';
- $mainId = $this->mainId ?? 0;
- $where = [];
- $requestType = $get['requestType'] ?? 'cp';
- $where['mainId'] = $mainId;
- if ($requestType == 'cp') {
- $where['delStatus'] = 0;
- }
- if ($requestType == 'del') {
- $where['delStatus'] = 1;
- }
- if (!empty($search)) {
- if (stringUtil::isLetter($search)) {
- $where['py'] = ['like', $search];
- } else {
- $where['name'] = ['like', $search];
- }
- } else {
- if (!empty($classId)) {
- $where['classId'] = $classId;
- }
- }
- $respond = CpClass::getCpList($where);
- util::success($respond);
- }
- //添加产品 ssh 20240106
- public function actionAddCp()
- {
- util::fail('开发中');
- $post = Yii::$app->request->post();
- $post['mainId'] = $this->mainId;
- $post['adminId'] = $this->adminId;
- if (isset($post['name']) == false || empty($post['name'])) {
- util::fail('请填写名称');
- }
- $post['py'] = stringUtil::py($post['name']);
- $staff = $this->shopAdmin;
- $staffName = $staff->name ?? '';
- $post['staffName'] = $staffName;
- $shop = $this->shop;
- unset($post['id']);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- CpClass::addCp($post, $shop);
- $transaction->commit();
- util::complete('添加成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- util::fail('添加没有成功');
- }
- }
- public function actionUpdateCp()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $cp = CpClass::getById($id, true);
- if (empty($cp)) {
- util::fail('没有找到产品');
- }
- if ($cp->mainId != $this->mainId) {
- util::fail('不是你的产品');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- unset($post['id']);
- CpClass::updateCp($post, $cp, $this->shop);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- util::fail('添加没有成功');
- }
- }
- public function actionRecoverCp()
- {
- $masterShop = $this->shop;
- if (isset($masterShop->default) == false || $masterShop->default == 0) {
- util::fail('请在总店操作');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cp = CpClass::getById($id, true);
- if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
- util::fail('无法查看');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- CpClass::recoverCp($cp, $this->shop);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("删除失败原因:" . $e->getMessage());
- util::fail('删除失败');
- }
- }
- public function actionDelCp()
- {
- $masterShop = $this->shop;
- if (isset($masterShop->default) == false || $masterShop->default == 0) {
- util::fail('请在总店操作');
- }
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cp = CpClass::getById($id, true);
- if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
- util::fail('无法查看');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- CpClass::delCp($cp, $this->shop);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::info("删除失败原因:" . $e->getMessage());
- util::fail('删除失败');
- }
- }
- //查看详情 ssh 20240219
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $cp = CpClass::getById($id);
- if (isset($cp['mainId']) == false || $cp['mainId'] != $this->mainId) {
- util::fail('无法查看');
- }
- $classId = $cp['classId'] ?? 0;
- $class = CpClassClass::getById($classId, true);
- $className = $class->name ?? '';
- $shortCover = $cp['cover'] ?? '';
- $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $cp['shortCover'] = $shortCover;
- $cp['cover'] = $bigCover;
- $cp['smallCover'] = $smallCover;
- $cp['bigCover'] = $bigCover;
- $cp['className'] = $className;
- util::success($cp);
- }
- }
|