CpController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\cp\classes\PtCpClass;
  4. use bizGhs\cp\classes\CpClass;
  5. use bizGhs\cp\classes\CpClassClass;
  6. use bizGhs\cp\services\CpService;
  7. use common\components\imgUtil;
  8. use common\components\stringUtil;
  9. use common\components\util;
  10. use Yii;
  11. class CpController extends BaseController
  12. {
  13. //采用平台花材 ssh 20240226
  14. public function actionAddPtCp()
  15. {
  16. $get = Yii::$app->request->get();
  17. $ptCpId = $get['id'] ?? 0;
  18. $ptCp = PtCpClass::getById($ptCpId, true);
  19. if (empty($ptCp)) {
  20. util::fail('没有找到产品');
  21. }
  22. $cp = CpService::addPtCp($ptCp, $this->shop);
  23. util::success(['cp' => $cp]);
  24. }
  25. //根据分类id取集合,带分页 ssh 20231228
  26. public function actionList()
  27. {
  28. $get = Yii::$app->request->get();
  29. $classId = $get['classId'] ?? 0;
  30. $search = $get['search'] ?? '';
  31. $mainId = $this->mainId ?? 0;
  32. $where = [];
  33. $requestType = $get['requestType'] ?? 'cp';
  34. $where['mainId'] = $mainId;
  35. if ($requestType == 'cp') {
  36. $where['delStatus'] = 0;
  37. }
  38. if ($requestType == 'del') {
  39. $where['delStatus'] = 1;
  40. }
  41. if (!empty($search)) {
  42. if (stringUtil::isLetter($search)) {
  43. $where['py'] = ['like', $search];
  44. } else {
  45. $where['name'] = ['like', $search];
  46. }
  47. } else {
  48. if (!empty($classId)) {
  49. $where['classId'] = $classId;
  50. }
  51. }
  52. $respond = CpClass::getCpList($where);
  53. util::success($respond);
  54. }
  55. //添加产品 ssh 20240106
  56. public function actionAddCp()
  57. {
  58. $post = Yii::$app->request->post();
  59. $post['mainId'] = $this->mainId;
  60. $post['adminId'] = $this->adminId;
  61. if (isset($post['name']) == false || empty($post['name'])) {
  62. util::fail('请填写名称');
  63. }
  64. $post['py'] = stringUtil::py($post['name']);
  65. $staff = $this->shopAdmin;
  66. $staffName = $staff->name ?? '';
  67. $post['staffName'] = $staffName;
  68. $shop = $this->shop;
  69. unset($post['id']);
  70. $connection = Yii::$app->db;//事务处理
  71. $transaction = $connection->beginTransaction();
  72. try {
  73. CpClass::addCp($post, $shop);
  74. $transaction->commit();
  75. util::complete('添加成功');
  76. } catch (\Exception $e) {
  77. $transaction->rollBack();
  78. util::fail('添加没有成功');
  79. }
  80. }
  81. public function actionUpdateCp()
  82. {
  83. $post = Yii::$app->request->post();
  84. $id = $post['id'] ?? 0;
  85. $cp = CpClass::getById($id, true);
  86. if (empty($cp)) {
  87. util::fail('没有找到产品');
  88. }
  89. if ($cp->mainId != $this->mainId) {
  90. util::fail('不是你的产品');
  91. }
  92. $connection = Yii::$app->db;//事务处理
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. unset($post['id']);
  96. CpClass::updateCp($post, $cp, $this->shop);
  97. $transaction->commit();
  98. util::complete();
  99. } catch (\Exception $e) {
  100. $transaction->rollBack();
  101. util::fail('添加没有成功');
  102. }
  103. }
  104. public function actionRecoverCp()
  105. {
  106. $masterShop = $this->shop;
  107. if (isset($masterShop->default) == false || $masterShop->default == 0) {
  108. util::fail('请在总店操作');
  109. }
  110. $get = Yii::$app->request->get();
  111. $id = $get['id'] ?? 0;
  112. $cp = CpClass::getById($id, true);
  113. if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
  114. util::fail('无法查看');
  115. }
  116. $connection = Yii::$app->db;//事务处理
  117. $transaction = $connection->beginTransaction();
  118. try {
  119. CpClass::recoverCp($cp, $this->shop);
  120. $transaction->commit();
  121. util::complete();
  122. } catch (\Exception $e) {
  123. $transaction->rollBack();
  124. Yii::info("删除失败原因:" . $e->getMessage());
  125. util::fail('删除失败');
  126. }
  127. }
  128. public function actionDelCp()
  129. {
  130. $masterShop = $this->shop;
  131. if (isset($masterShop->default) == false || $masterShop->default == 0) {
  132. util::fail('请在总店操作');
  133. }
  134. $get = Yii::$app->request->get();
  135. $id = $get['id'] ?? 0;
  136. $cp = CpClass::getById($id, true);
  137. if (isset($cp->mainId) == false || $cp->mainId != $this->mainId) {
  138. util::fail('无法查看');
  139. }
  140. $connection = Yii::$app->db;//事务处理
  141. $transaction = $connection->beginTransaction();
  142. try {
  143. CpClass::delCp($cp, $this->shop);
  144. $transaction->commit();
  145. util::complete();
  146. } catch (\Exception $e) {
  147. $transaction->rollBack();
  148. Yii::info("删除失败原因:" . $e->getMessage());
  149. util::fail('删除失败');
  150. }
  151. }
  152. //查看详情 ssh 20240219
  153. public function actionDetail()
  154. {
  155. $get = Yii::$app->request->get();
  156. $id = $get['id'] ?? 0;
  157. $cp = CpClass::getById($id);
  158. if (isset($cp['mainId']) == false || $cp['mainId'] != $this->mainId) {
  159. util::fail('无法查看');
  160. }
  161. $classId = $cp['classId'] ?? 0;
  162. $class = CpClassClass::getById($classId, true);
  163. $className = $class->name ?? '';
  164. $shortCover = $cp['cover'] ?? '';
  165. $smallCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  166. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  167. $cp['shortCover'] = $shortCover;
  168. $cp['cover'] = $bigCover;
  169. $cp['smallCover'] = $smallCover;
  170. $cp['bigCover'] = $bigCover;
  171. $cp['className'] = $className;
  172. util::success($cp);
  173. }
  174. }