ApiCommissionBusinessman.Class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /**
  3. * api分销商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 JinDouYun\Model\Commission\MCommissionGrade;
  12. use JinDouYun\Model\Commission\MCommissionOrder;
  13. use Mall\Framework\Core\ErrorCode;
  14. use Mall\Framework\Core\ResultWrapper;
  15. use Mall\Framework\Core\StatusCode;
  16. use JinDouYun\Controller\BaseController;
  17. use JinDouYun\Model\Commission\MCommissionBusinessman;
  18. class ApiCommissionBusinessman extends BaseController
  19. {
  20. /**
  21. * @var MCommissionBusinessman
  22. */
  23. private $objMCommissionBusinessman;
  24. /**
  25. * @var MCommissionOrder
  26. */
  27. private $objMCommissionOrder;
  28. /**
  29. * ApiCommissionBusinessman constructor.
  30. * @param bool $isCheckAcl
  31. * @param bool $isMustLogin
  32. * @param bool $checkToken
  33. * @throws Exception
  34. */
  35. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken=true)
  36. {
  37. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  38. $this->objMCommissionBusinessman = new MCommissionBusinessman($this->onlineEnterpriseId, $this->onlineUserId);
  39. $this->objMCommissionOrder = new MCommissionOrder($this->onlineEnterpriseId,$this->onlineUserId);
  40. }
  41. /**
  42. * 获取参数
  43. */
  44. public function commonFieldFilter()
  45. {
  46. $params = $this->request->getRawJson();
  47. if (empty($params)) {
  48. parent::sendOutput('参数为空', ErrorCode::$paramError);
  49. }
  50. $data = [
  51. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  52. ];
  53. foreach($data as $key => $value){
  54. if(empty($value) && $value !== 0){
  55. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  56. }
  57. }
  58. (isset($params['info']) && !empty($params['info'])) && $data['info'] = $params['info'];
  59. (isset($params['gradeId']) && !empty($params['gradeId'])) && $data['gradeId'] = $params['gradeId'];
  60. (isset($params['grade']) && !empty($params['grade'])) && $data['grade'] = $params['grade'];
  61. return $data;
  62. }
  63. /**
  64. * 申请分销商
  65. * @throws Exception
  66. */
  67. public function applicationBusinessman()
  68. {
  69. $data = self::commonFieldFilter();
  70. $modelResult = $this->objMCommissionBusinessman->addBusinessman($data);
  71. if(!$modelResult->isSuccess()){
  72. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  73. }
  74. parent::sendOutput($modelResult->getData());
  75. }
  76. /**
  77. * 添加上下级关系
  78. * @throws Exception
  79. */
  80. public function relationshipBusinessman()
  81. {
  82. $params = $this->request->getRawJson();
  83. if(empty($params)){
  84. parent::sendOutput('参数为空', ErrorCode::$paramError);
  85. }
  86. $data = [
  87. 'businessmanId' => getArrayItem($params, 'businessmanId'),
  88. 'source' => getArrayItem($params, 'source'),
  89. ];
  90. foreach($data as $key => $value){
  91. if(empty($value) && $value !== 0){
  92. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  93. }
  94. }
  95. $modelResult = $this->objMCommissionBusinessman->relationshipBusinessman($data);
  96. if(!$modelResult->isSuccess()){
  97. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  98. }
  99. parent::sendOutput($modelResult->getData());
  100. }
  101. /**
  102. * 修改分销商
  103. * @throws Exception
  104. */
  105. public function updateBusinessman()
  106. {
  107. $id = $this->request->param('request_id');
  108. if(empty($id)){
  109. parent::sendOutput('参数为空', ErrorCode::$paramError);
  110. }
  111. $data = self::commonFieldFilter();
  112. $modelResult = $this->objMCommissionBusinessman->updateBusinessman($data, ['id' => $id]);
  113. if(!$modelResult->isSuccess()){
  114. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  115. }
  116. parent::sendOutput($modelResult->getData());
  117. }
  118. /**
  119. * 分销商详情
  120. */
  121. public function getInfoBusinessman()
  122. {
  123. $where['userCenterId'] = $this->onlineUserId;
  124. $modelResult = $this->objMCommissionBusinessman->getInfoBusinessman($where);
  125. if(!$modelResult->isSuccess()){
  126. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  127. }
  128. parent::sendOutput($modelResult->getData());
  129. }
  130. /**
  131. * 查询分销商的所有下级
  132. * @throws Exception
  133. */
  134. public function getAllSub()
  135. {
  136. $params = $this->request->getRawJson();
  137. if(empty($params)){
  138. parent::sendOutput('参数为空', ErrorCode::$paramError);
  139. }
  140. $data = [
  141. 'id' => isset($params['id']) ? $params['id'] : '',
  142. 'level' => isset($params['level']) ? $params['level'] : '',
  143. 'page' => isset($params['page']) ? $params['page'] : '',
  144. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : '',
  145. ];
  146. foreach($data as $key => $value){
  147. if(empty($value) && $value !== 0){
  148. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  149. }
  150. }
  151. $pageParams = pageToOffset($params['page'],$params['pageSize']);
  152. $data['limit'] = $pageParams['limit'];
  153. $data['offset'] = $pageParams['offset'];
  154. $modelResult = $this->objMCommissionBusinessman->getAllSub($data);
  155. if(!$modelResult->isSuccess()){
  156. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  157. }
  158. $returnData = $modelResult->getData();
  159. $pageData = [
  160. 'pageIndex' => $params['page'],
  161. 'pageSize' => $params['pageSize'],
  162. 'pageTotal' => $returnData['total'],
  163. 'subTotal' => $returnData['subTotal'],
  164. 'businessmanTotal' => $returnData['businessmanTotal'],
  165. 'subBusinessmanTotal' => $returnData['subBusinessmanTotal'],
  166. ];
  167. parent::sendOutput($returnData['data'], 0, $pageData);
  168. }
  169. /**
  170. * 排行榜
  171. */
  172. public function commissionTop()
  173. {
  174. $modelResult = $this->objMCommissionBusinessman->statisticsCommissionThree();
  175. if(!$modelResult->isSuccess()){
  176. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  177. }
  178. parent::sendOutput($modelResult->getData());
  179. }
  180. /**
  181. * 等级说明
  182. */
  183. public function getAllGrade()
  184. {
  185. $modelResult = $this->objMCommissionBusinessman->getBusinessmanGradeInfo();
  186. if(!$modelResult->isSuccess()){
  187. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  188. }
  189. parent::sendOutput($modelResult->getData());
  190. }
  191. /**
  192. * Doc: (des="分销中心订单列表")
  193. * User: XMing
  194. * Date: 2020/7/30
  195. * Time: 10:47 上午
  196. * @throws Exception
  197. */
  198. public function getCommissionOrder()
  199. {
  200. $params = $this->request->getRawJson();
  201. if(empty($params)){
  202. parent::sendOutput('参数为空', ErrorCode::$paramError);
  203. }
  204. $pageParams = pageToOffset($params['page'] ? $params['page'] : 1, $params['pageSize'] ? $params['pageSize'] : 10);
  205. $params['limit'] = $pageParams['limit'];
  206. $params['offset'] = $pageParams['offset'];
  207. $modelResult = $this->objMCommissionOrder->getCommissionOrder($params);
  208. if(!$modelResult->isSuccess()){
  209. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  210. }
  211. $returnData = $modelResult->getData();
  212. $pageData = [
  213. 'pageIndex' => $params['page'],
  214. 'pageSize' => $params['pageSize'],
  215. 'pageTotal' => $returnData['total'],
  216. ];
  217. parent::sendOutput($returnData['data'], 0, $pageData);
  218. }
  219. /**
  220. * Doc: (des="分销订单详情")
  221. * User: XMing
  222. * Date: 2020/7/30
  223. * Time: 4:06 下午
  224. * @throws Exception
  225. */
  226. public function getCommissionOrderInfo()
  227. {
  228. $id = $this->request->param('request_id');
  229. if(empty($id)){
  230. parent::sendOutput('参数为空', ErrorCode::$paramError);
  231. }
  232. $modelResult = $this->objMCommissionOrder->getCommissionOrderInfo($id);
  233. if(!$modelResult->isSuccess()){
  234. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  235. }
  236. parent::sendOutput($modelResult->getData());
  237. }
  238. /**
  239. * 修改直系上级关系
  240. * @throws Exception
  241. * 客户id,上级id
  242. */
  243. public function editRelationship()
  244. {
  245. $params = $this->request->getRawJson();
  246. if(empty($params['id']) || empty($params['superiorId']) ){
  247. parent::sendOutput('分销商参数错误', ErrorCode::$paramError);
  248. }
  249. $result = $this->objMCommissionBusinessman->editRelationship($params);
  250. if(!$result->isSuccess()){
  251. parent::sendOutput($result->getData(), $result->getErrorCode());
  252. }
  253. parent::sendOutput($result->getData());
  254. }
  255. }