CommissionBusinessman.Class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /**
  3. * 分销商Controller
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2020/07/22
  7. * Time: 15:00
  8. */
  9. namespace JinDouYun\Controller\Commission;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use Mall\Framework\Core\StatusCode;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Commission\MCommissionBusinessman;
  16. class CommissionBusinessman extends BaseController
  17. {
  18. private $objMCommissionBusinessman;
  19. public function __construct($isCheckAcl = true, $isMustLogin = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin);
  22. $this->objMCommissionBusinessman = new MCommissionBusinessman($this->onlineEnterpriseId, $this->onlineUserId);
  23. }
  24. /**
  25. * 获取参数
  26. */
  27. public function commonFieldFilter()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. parent::sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $data = [
  34. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  35. ];
  36. foreach($data as $key => $value){
  37. if(empty($value) && $value !== 0){
  38. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  39. }
  40. }
  41. (isset($params['info']) && !empty($params['info'])) && $data['info'] = $params['info'];
  42. (isset($params['gradeId']) && !empty($params['gradeId'])) && $data['gradeId'] = $params['gradeId'];
  43. (isset($params['grade']) && !empty($params['grade'])) && $data['grade'] = $params['grade'];
  44. return $data;
  45. }
  46. /**
  47. * 新增分销商
  48. * @throws Exception
  49. */
  50. public function addBusinessman()
  51. {
  52. $data = self::commonFieldFilter();
  53. $modelResult = $this->objMCommissionBusinessman->addBusinessman($data);
  54. if(!$modelResult->isSuccess()){
  55. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  56. }
  57. parent::sendOutput($modelResult->getData());
  58. }
  59. /**
  60. * 删除分销商
  61. * @throws Exception
  62. */
  63. public function delBusinessman()
  64. {
  65. $params = $this->request->getRawJson();
  66. $where = [];
  67. isset($params['userCenterId']) && $where['userCenterId'] = $params['userCenterId'];
  68. if(!isset($where['userCenterId'])){
  69. parent::sendOutput('userCenterId参数错误', ErrorCode::$paramError);
  70. }
  71. $update = [
  72. 'deleteStatus' => StatusCode::$delete
  73. ];
  74. $modelResult = $this->objMCommissionBusinessman->updateBusinessman($update, $where);
  75. if(!$modelResult->isSuccess()){
  76. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  77. }
  78. parent::sendOutput($modelResult->getData());
  79. }
  80. /**
  81. * 分销商审核
  82. * @throws Exception
  83. */
  84. public function auditBusinessman()
  85. {
  86. $params = $this->request->getRawJson();
  87. $where = [];
  88. isset($params['userCenterId']) && $where['userCenterId'] = $params['userCenterId'];
  89. $update = [
  90. 'auditStatus' => StatusCode::$auditStatus['auditPass']
  91. ];
  92. if(empty($where)){
  93. parent::sendOutput('参数为空', ErrorCode::$paramError);
  94. }
  95. if(!isset($where['userCenterId'])){
  96. parent::sendOutput('userCenterId参数错误', ErrorCode::$paramError);
  97. }
  98. $modelResult = $this->objMCommissionBusinessman->updateBusinessman($update, $where);
  99. if(!$modelResult->isSuccess()){
  100. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  101. }
  102. parent::sendOutput($modelResult->getData());
  103. }
  104. /**
  105. * 修改分销商
  106. * @throws Exception
  107. */
  108. public function updateBusinessman()
  109. {
  110. $id = $this->request->param('request_id');
  111. if(empty($id)){
  112. parent::sendOutput('参数为空', ErrorCode::$paramError);
  113. }
  114. $data = self::commonFieldFilter();
  115. $modelResult = $this->objMCommissionBusinessman->updateBusinessman($data, ['userCenterId' => $id]);
  116. if(!$modelResult->isSuccess()){
  117. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  118. }
  119. parent::sendOutput($modelResult->getData());
  120. }
  121. /**
  122. * 分销商列表
  123. */
  124. public function getAllBusinessman()
  125. {
  126. $params = $this->request->getRawJson();
  127. if(empty($params)){
  128. $this->sendOutput('参数为空', ErrorCode::$paramError);
  129. }
  130. $selectParams = [];
  131. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  132. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  133. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  134. $selectParams['limit'] = $pageParams['limit'];
  135. $selectParams['offset'] = $pageParams['offset'];
  136. if(isset($params['auditStatus']) && !empty($params['auditStatus'])){
  137. $selectParams['auditStatus'] = $params['auditStatus'];
  138. }
  139. if(isset($params['search']) && !empty($params['search'])){
  140. $selectParams['search'] = $params['search'];
  141. }
  142. if(isset($params['grade']) && !empty($params['grade'])){
  143. $selectParams['grade'] = $params['grade'];
  144. }
  145. if(isset($params['createStar']) && !empty($params['createStar']) && isset($params['createEnd']) && !empty($params['createEnd'])){
  146. $selectParams['createStar'] = $params['createStar'];
  147. $selectParams['createEnd'] = $params['createEnd'];
  148. }
  149. if(isset($params['applicationStar']) && !empty($params['applicationStar']) && isset($params['applicationEnd']) && !empty($params['applicationEnd'])){
  150. $selectParams['applicationStar'] = $params['applicationStar'];
  151. $selectParams['applicationEnd'] = $params['applicationEnd'];
  152. }
  153. if(isset($params['auditStar']) && !empty($params['auditStar']) && isset($params['auditEnd']) && !empty($params['auditEnd'])){
  154. $selectParams['auditStar'] = $params['auditStar'];
  155. }
  156. $export = isset($params['export']) ? $params['export'] : 0;// 导出未审核
  157. $distribution = isset($params['distribution']) ? $params['distribution'] : 0; // 导出分销商
  158. $modelResult = $this->objMCommissionBusinessman->getAllBusinessman($selectParams,$export,$distribution);
  159. if(!$modelResult->isSuccess()){
  160. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  161. }
  162. $returnData = $modelResult->getData();
  163. $pageData = [
  164. 'pageIndex' => $params['page'],
  165. 'pageSize' => $params['pageSize'],
  166. 'pageTotal' => $returnData['total'],
  167. ];
  168. parent::sendOutput($returnData['data'], 0, $pageData);
  169. }
  170. /**
  171. * 查询分销商的所有下级
  172. * @throws Exception
  173. */
  174. public function getAllSub()
  175. {
  176. $params = $this->request->getRawJson();
  177. if(empty($params)){
  178. parent::sendOutput('参数为空', ErrorCode::$paramError);
  179. }
  180. $data = [
  181. 'id' => isset($params['id']) ? $params['id'] : '',
  182. 'level' => isset($params['level']) ? $params['level'] : '',
  183. 'page' => isset($params['page']) ? $params['page'] : '',
  184. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : '',
  185. ];
  186. foreach($data as $key => $value){
  187. if(empty($value) && $value !== 0){
  188. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  189. }
  190. }
  191. $pageParams = pageToOffset($params['page'],$params['pageSize']);
  192. $data['limit'] = $pageParams['limit'];
  193. $data['offset'] = $pageParams['offset'];
  194. $modelResult = $this->objMCommissionBusinessman->getAllSub($data);
  195. if(!$modelResult->isSuccess()){
  196. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  197. }
  198. $returnData = $modelResult->getData();
  199. $pageData = [
  200. 'pageIndex' => $params['page'],
  201. 'pageSize' => $params['pageSize'],
  202. 'pageTotal' => $returnData['total'],
  203. 'subTotal' => $returnData['subTotal'],
  204. 'businessmanTotal' => $returnData['businessmanTotal'],
  205. 'subBusinessmanTotal' => $returnData['subBusinessmanTotal'],
  206. ];
  207. parent::sendOutput($returnData['data'], 0, $pageData);
  208. }
  209. /**
  210. * 分销商详情
  211. */
  212. public function getInfoBusinessman()
  213. {
  214. $where = [];
  215. $params = $this->request->getRawJson();
  216. isset($params['userCenterId']) && $where['userCenterId'] = $params['userCenterId'];
  217. if(empty($where)){
  218. parent::sendOutput('参数为空', ErrorCode::$paramError);
  219. }
  220. $modelResult = $this->objMCommissionBusinessman->getInfoBusinessman($where);
  221. if(!$modelResult->isSuccess()){
  222. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  223. }
  224. parent::sendOutput($modelResult->getData());
  225. }
  226. /**
  227. * 首页统计
  228. */
  229. public function statisticsCommissionOne()
  230. {
  231. $modelResult = $this->objMCommissionBusinessman->statisticsCommissionOne();
  232. if(!$modelResult->isSuccess()){
  233. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  234. }
  235. parent::sendOutput($modelResult->getData());
  236. }
  237. /**
  238. * 首页统计(新增分销商数)
  239. */
  240. public function statisticsCommissionTwo()
  241. {
  242. $modelResult = $this->objMCommissionBusinessman->statisticsCommissionTwo();
  243. if(!$modelResult->isSuccess()){
  244. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  245. }
  246. parent::sendOutput($modelResult->getData());
  247. }
  248. /**
  249. * 首页统计(TOP)
  250. */
  251. public function statisticsCommissionThree()
  252. {
  253. $modelResult = $this->objMCommissionBusinessman->statisticsCommissionThree();
  254. if(!$modelResult->isSuccess()){
  255. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  256. }
  257. parent::sendOutput($modelResult->getData());
  258. }
  259. /**
  260. * 查询分销商下级人数
  261. */
  262. public function getBusinessmanSubLevelNum()
  263. {
  264. $modelResult = $this->objMCommissionBusinessman->getBusinessmanSubLevelNum();
  265. if(!$modelResult->isSuccess()){
  266. parent::sendOutput($modelResult->getData(),$modelResult->getErrorCode());
  267. }
  268. parent::sendOutput($modelResult->getData());
  269. }
  270. }