|
|
@@ -54,13 +54,50 @@ class CpController extends BaseController
|
|
|
$post['staffName'] = $staffName;
|
|
|
$shop = $this->shop;
|
|
|
unset($post['id']);
|
|
|
- CpClass::addCp($post, $shop);
|
|
|
- util::complete('添加成功');
|
|
|
+ $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()
|
|
|
{
|
|
|
- util::complete();
|
|
|
+ $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 actionDelCp()
|
|
|
+ {
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $id = $get['id'] ?? 0;
|
|
|
+ $cp = CpClass::getById($id);
|
|
|
+ if (isset($cp['mainId']) == false || $cp['mainId'] != $this->mainId) {
|
|
|
+ util::fail('无法查看');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//查看详情 ssh 20240219
|
|
|
@@ -69,13 +106,13 @@ class CpController extends BaseController
|
|
|
$get = Yii::$app->request->get();
|
|
|
$id = $get['id'] ?? 0;
|
|
|
$cp = CpClass::getById($id);
|
|
|
- if ($cp['mainId'] != $this->mainId) {
|
|
|
+ if (isset($cp['mainId']) == false || $cp['mainId'] != $this->mainId) {
|
|
|
util::fail('无法查看');
|
|
|
}
|
|
|
$classId = $cp['classId'] ?? 0;
|
|
|
$class = CpClassClass::getById($classId, true);
|
|
|
$className = $class->name ?? '';
|
|
|
- $shortCover = $class->cover ?? '';
|
|
|
+ $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;
|