CustomerSource.Class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * 客户渠道(类型)模块
  4. * Created by PhpStorm.
  5. * User: tpl
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\System;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\System\MCustomerSource;
  14. class CustomerSource extends BaseController
  15. {
  16. private $objMCustomerSource;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMCustomerSource = new MCustomerSource($this->onlineEnterpriseId);
  21. }
  22. /**
  23. * 添加和编辑客户渠道(类型)管理公共字段处理方法
  24. *
  25. * @return array
  26. */
  27. public function commonFieldFilter(){
  28. $params = $this->request->getRawJson();
  29. if( empty($params) ){
  30. $this->sendOutput('参数为空', ErrorCode::$paramError );
  31. }
  32. $customerSourceData = [
  33. 'name' => isset($params['name']) ? $params['name'] : '',
  34. 'defaultStatus' => isset($params['defaultStatus']) ? $params['defaultStatus'] : '',
  35. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  36. ];
  37. foreach($customerSourceData as $key => $value){
  38. if(empty($value) && $value !== 0){
  39. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  40. }
  41. }
  42. $customerSourceData['modelType'] = getArrayItem($params,'modelType',0);
  43. $customerSourceData['enterpriseId'] = $this->onlineEnterpriseId;
  44. $customerSourceData['deleteStatus']= StatusCode::$standard;
  45. $customerSourceData['createTime'] = time();
  46. $customerSourceData['updateTime'] = time();
  47. return $customerSourceData;
  48. }
  49. /**
  50. * 添加客户渠道(类型)
  51. * @throws \Exception
  52. */
  53. public function addCustomerSource()
  54. {
  55. $customerSourceData = $this->commonFieldFilter();
  56. $result = $this->objMCustomerSource->addCustomerSource($customerSourceData);
  57. if($result->isSuccess()){
  58. parent::sendOutput($result->getData());
  59. }else{
  60. parent::sendOutput($result->getData(), $result->getErrorCode());
  61. }
  62. }
  63. /**
  64. * 获取指定客户渠道(类型)信息
  65. */
  66. public function getCustomerSourceInfo()
  67. {
  68. $customerSourceId = $this->request->param('request_id');
  69. if ( !$customerSourceId ) {
  70. $this->sendOutput('参数错误', ErrorCode::$paramError );
  71. }
  72. $result = $this->objMCustomerSource->getCustomerSourceInfo($customerSourceId);
  73. if($result->isSuccess()){
  74. $this->sendOutput($result->getData());
  75. }else{
  76. $this->sendOutput($result->getData(), $result->getErrorCode());
  77. }
  78. }
  79. /**
  80. * 编辑客户渠道(类型)
  81. */
  82. public function editCustomerSource()
  83. {
  84. $customerSourceId = $this->request->param('request_id');
  85. if(empty($customerSourceId)){
  86. $this->sendOutput('参数错误', ErrorCode::$paramError);
  87. }
  88. $customerSourceData = $this->commonFieldFilter();
  89. $customerSourceData['id'] = $customerSourceId;
  90. unset($customerSourceData['createTime']);
  91. $result = $this->objMCustomerSource->editCustomerSource($customerSourceData);
  92. if($result->isSuccess()){
  93. parent::sendOutput($result->getData());
  94. }else{
  95. parent::sendOutput($result->getData(), $result->getErrorCode());
  96. }
  97. }
  98. /**
  99. * 删除客户渠道(类型)
  100. */
  101. public function delCustomerSource()
  102. {
  103. $customerSourceId = $this->request->param('request_id');
  104. if(!$customerSourceId){
  105. $this->sendOutput('参数错误', ErrorCode::$paramError);
  106. }
  107. $result = $this->objMCustomerSource->delCustomerSource($customerSourceId);
  108. if($result->isSuccess()){
  109. parent::sendOutput($result->getData());
  110. }else{
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. }
  114. /**
  115. * 客户渠道(类型)启用和禁用
  116. */
  117. public function updateCustomerSourceStatus()
  118. {
  119. $params = $this->request->getRawJson();
  120. if( empty($params['id']) && empty($params['enableStatus'])){
  121. $this->sendOutput('参数为空', ErrorCode::$paramError );
  122. }
  123. $result = $this->objMCustomerSource->updateCustomerSourceStatus($params);
  124. if($result->isSuccess()){
  125. parent::sendOutput($result->getData());
  126. }else{
  127. parent::sendOutput($result->getData(), $result->getErrorCode());
  128. }
  129. }
  130. /**
  131. * 客户渠道(类型)是否默认
  132. */
  133. public function updateDefaultStatus()
  134. {
  135. $params = $this->request->getRawJson();
  136. if( empty($params['id']) && empty($params['defaultStatus'])){
  137. $this->sendOutput('参数为空', ErrorCode::$paramError );
  138. }
  139. $result = $this->objMCustomerSource->updateDefaultStatus($params);
  140. if($result->isSuccess()){
  141. parent::sendOutput($result->getData());
  142. }else{
  143. parent::sendOutput($result->getData(), $result->getErrorCode());
  144. }
  145. }
  146. /**
  147. * 后台所有客户渠道(类型)列表 分页
  148. */
  149. public function getAllCustomerSource()
  150. {
  151. $params = $this->request->getRawJson();
  152. if( empty($params) ){
  153. $this->sendOutput('参数为空', ErrorCode::$paramError );
  154. }
  155. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  156. $selectParams['limit'] = $pageParams['limit'];
  157. $selectParams['offset'] = $pageParams['offset'];
  158. $result = $this->objMCustomerSource->getAllCustomerSource($selectParams);
  159. if($result->isSuccess()){
  160. $returnData = $result->getData();
  161. $pageData = [
  162. 'pageIndex' => $params['page'],
  163. 'pageSize' => $params['pageSize'],
  164. 'pageTotal' => $returnData['total'],
  165. ];
  166. parent::sendOutput($returnData['data'], 0, $pageData);
  167. }else{
  168. parent::sendOutput($result->getData(), $result->getErrorCode());
  169. }
  170. }
  171. /**
  172. * 后台所有客户渠道(类型)列表 不分页
  173. */
  174. public function getCustomerSourceList()
  175. {
  176. $result = $this->objMCustomerSource->getCustomerSourceList();
  177. if($result->isSuccess()){
  178. parent::sendOutput($result->getData());
  179. }else{
  180. parent::sendOutput($result->getData(), $result->getErrorCode());
  181. }
  182. }
  183. }