SpecManage.Class.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace JinDouYun\Controller\GoodsManage;
  3. use Mall\Framework\Core\StatusCode;
  4. use JinDouYun\Controller\BaseController;
  5. use JinDouYun\Model\GoodsManage\MSpec;
  6. use Mall\Framework\Core\ErrorCode;
  7. /**
  8. * 规格管理
  9. * type 5=>属性名 4=>属性值
  10. * Class SpecManage
  11. * @package JinDouYun\Controller\GoodsManage
  12. */
  13. class SpecManage extends BaseController
  14. {
  15. /**
  16. * @var MSpec
  17. */
  18. private $objMSpec;
  19. /**
  20. * SpecManage constructor.
  21. * @param bool $isCheckAcl
  22. * @param bool $isMustLogin
  23. * @param bool $checkToken
  24. * @param bool $getAreaCode
  25. * @throws \Exception
  26. */
  27. public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false)
  28. {
  29. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
  30. $this->objMSpec = new MSpec($this->onlineUserId, $this->onlineEnterpriseId);
  31. }
  32. /**
  33. * 添加和编辑规格
  34. *
  35. * @return array
  36. */
  37. public function commonFieldFilter()
  38. {
  39. $params = $this->request->getRawJson();
  40. if (empty($params)) {
  41. parent::sendOutput('参数为空', ErrorCode::$paramError);
  42. }
  43. $data = [
  44. 'specName' => isset($params['specName']) ? $params['specName'] : null,
  45. 'pid' => isset($params['pid']) ? $params['pid'] : 0,
  46. ];
  47. foreach ($data as $key => $value) {
  48. if (empty($value) && $value !== 0) {
  49. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  50. }
  51. }
  52. $data['hidden'] = isset($params['hidden']) ? $params['hidden'] : StatusCode::$standard;//5 不隐藏 4隐藏
  53. return $data;
  54. }
  55. /**
  56. * 规格管理列表
  57. */
  58. public function getAll()
  59. {
  60. $params = $this->request->getRawJson();
  61. if (empty($params)) {
  62. parent::sendOutput('参数为空', ErrorCode::$paramError);
  63. }
  64. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  65. $selectParams['limit'] = $pageParams['limit'];
  66. $selectParams['offset'] = $pageParams['offset'];
  67. $result = $this->objMSpec->getAll($selectParams);
  68. if ($result->isSuccess()) {
  69. $returnData = $result->getData();
  70. $pageData = [
  71. 'pageIndex' => $params['page'],
  72. 'pageSize' => $params['pageSize'],
  73. 'pageTotal' => $returnData['total'],
  74. ];
  75. parent::sendOutput($returnData['data'], 0, $pageData);
  76. }
  77. parent::sendOutput($result->getData(), $result->getErrorCode());
  78. }
  79. /**
  80. * 添加规格
  81. * @param $params
  82. */
  83. public function add()
  84. {
  85. $data = $this->commonFieldFilter();
  86. $result = $this->objMSpec->add($data);
  87. if ($result->isSuccess()) {
  88. parent::sendOutput($result->getData());
  89. }
  90. parent::sendOutput($result->getData(), $result->getErrorCode());
  91. }
  92. /**
  93. * 编辑
  94. */
  95. public function edit()
  96. {
  97. $id = $this->request->param('request_id');
  98. if (empty($id)) {
  99. $this->sendOutput('参数错误', ErrorCode::$paramError);
  100. }
  101. $data = $this->commonFieldFilter();
  102. $data['id'] = $id;
  103. $result = $this->objMSpec->edit($data);
  104. if ($result->isSuccess()) {
  105. parent::sendOutput($result->getData());
  106. }
  107. parent::sendOutput($result->getData(), $result->getErrorCode());
  108. }
  109. /**
  110. * 详情
  111. */
  112. public function info()
  113. {
  114. $id = $this->request->param('request_id');
  115. if (empty($id)) {
  116. $this->sendOutput('参数错误', ErrorCode::$paramError);
  117. }
  118. $result = $this->objMSpec->info($id);
  119. if ($result->isSuccess()) {
  120. parent::sendOutput($result->getData());
  121. }
  122. parent::sendOutput($result->getData(), $result->getErrorCode());
  123. }
  124. /**
  125. * 删除
  126. */
  127. public function del()
  128. {
  129. $id = $this->request->param('request_id');
  130. if (empty($id)) {
  131. $this->sendOutput('参数错误', ErrorCode::$paramError);
  132. }
  133. $result = $this->objMSpec->del($id);
  134. if ($result->isSuccess()) {
  135. parent::sendOutput($result->getData());
  136. }
  137. parent::sendOutput($result->getData(), $result->getErrorCode());
  138. }
  139. /**
  140. * 获取属性名
  141. */
  142. public function getAllSpecName()
  143. {
  144. $params = $this->request->getRawJson();
  145. if (empty($params)) {
  146. parent::sendOutput('参数为空', ErrorCode::$paramError);
  147. }
  148. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  149. $selectParams['limit'] = $pageParams['limit'];
  150. $selectParams['offset'] = $pageParams['offset'];
  151. $result = $this->objMSpec->getAllSpecName($selectParams);
  152. if ($result->isSuccess()) {
  153. $returnData = $result->getData();
  154. $pageData = [
  155. 'pageIndex' => $params['page'],
  156. 'pageSize' => $params['pageSize'],
  157. 'pageTotal' => $returnData['total'],
  158. ];
  159. parent::sendOutput($returnData['data'], 0, $pageData);
  160. }
  161. parent::sendOutput($result->getData(), $result->getErrorCode());
  162. }
  163. /**
  164. * pid => specValue
  165. */
  166. public function getAllSpecValByPid()
  167. {
  168. $params = $this->request->getRawJson();
  169. if (empty($params)) {
  170. parent::sendOutput('参数为空', ErrorCode::$paramError);
  171. }
  172. if (!isset($params['pid'])){
  173. parent::sendOutput('pid参数错误', ErrorCode::$paramError);
  174. }
  175. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  176. $selectParams['limit'] = $pageParams['limit'];
  177. $selectParams['offset'] = $pageParams['offset'];
  178. $selectParams['pid'] = $params['pid'];
  179. $result = $this->objMSpec->getAllSpecValByPid($selectParams);
  180. if ($result->isSuccess()) {
  181. $returnData = $result->getData();
  182. $pageData = [
  183. 'pageIndex' => $params['page'],
  184. 'pageSize' => $params['pageSize'],
  185. 'pageTotal' => $returnData['total'],
  186. ];
  187. parent::sendOutput($returnData['data'], 0, $pageData);
  188. }
  189. parent::sendOutput($result->getData(), $result->getErrorCode());
  190. }
  191. /**
  192. * 5 => 隐藏 4=>不隐藏
  193. * 添加自定义属性
  194. */
  195. public function defineSpec()
  196. {
  197. $data = $this->commonFieldFilter();
  198. $result = $this->objMSpec->defineSpec($data);
  199. if ($result->isSuccess()) {
  200. parent::sendOutput($result->getData());
  201. }
  202. parent::sendOutput($result->getData(), $result->getErrorCode());
  203. }
  204. }