ApiNewCommissionPartner.Class.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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\NewCommission;
  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 Util\Common\PartnerTools;
  16. use JinDouYun\Model\Customer\MCustomer;
  17. class ApiNewCommissionPartner extends BaseController
  18. {
  19. private $customerData;
  20. private $partnerTool;
  21. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken=true)
  22. {
  23. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  24. $this->partnerTool = new PartnerTools($this->onlineEnterpriseId);
  25. $this->customerData = $this->partnerTool->getCustomerDataByUserCenterId($this->onlineUserId);
  26. }
  27. /**
  28. * 获取账户信息
  29. */
  30. public function getCommissionPartnerData(){
  31. if($this->customerData["isPartner"]==0){
  32. parent::sendOutput('您还不是合伙人', ErrorCode::$paramError);
  33. }
  34. $data = $this->partnerTool->getPartnerData($this->customerData["id"],$this->onlineUserId);
  35. if(empty($data)){
  36. parent::sendOutput('数据不存在', ErrorCode::$paramError);
  37. }
  38. parent::sendOutput($data);
  39. }
  40. /**
  41. * 获取分佣明细
  42. */
  43. public function getCommissionPartnerDetail(){
  44. $params = $this->request->getRawJson();
  45. if(empty($params)){
  46. parent::sendOutput('参数为空', ErrorCode::$paramError);
  47. }
  48. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  49. $selectParams['limit'] = $pageParams['limit'];
  50. $selectParams['offset'] = $pageParams['offset'];
  51. $where=[];
  52. if(!empty($params['code']) && in_array($params['code'], ["consume","income"])){
  53. if($params['code']=="consume"){
  54. $where["type"] = 0;
  55. }
  56. if($params['code']=="income"){
  57. $where["type"] = 1;
  58. }
  59. }
  60. $selectParams["where"] = $where;
  61. $data = $this->partnerTool->getCommissionDetail($this->customerData["id"],$selectParams);
  62. parent::sendOutput($data);
  63. }
  64. /**
  65. * 获取分佣账户余额明细
  66. */
  67. public function getCommissionPartnerBalanceDetail(){
  68. $params = $this->request->getRawJson();
  69. if(empty($params)){
  70. parent::sendOutput('参数为空', ErrorCode::$paramError);
  71. }
  72. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  73. $selectParams['limit'] = $pageParams['limit'];
  74. $selectParams['offset'] = $pageParams['offset'];
  75. $data = $this->partnerTool->getCommissionBalanceDetail($this->customerData["id"],$selectParams);
  76. parent::sendOutput($data);
  77. }
  78. /**
  79. * 获取提现记录
  80. */
  81. public function getPartnerApplyCashList(){
  82. $params = $this->request->getRawJson();
  83. if(empty($params)){
  84. parent::sendOutput('参数为空', ErrorCode::$paramError);
  85. }
  86. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  87. $selectParams['limit'] = $pageParams['limit'];
  88. $selectParams['offset'] = $pageParams['offset'];
  89. $data = $this->partnerTool->getCommissionBalanceDetail($this->customerData["id"],$selectParams);
  90. parent::sendOutput($data);
  91. }
  92. public function partnerApplyCash(){
  93. // $cache = Factory::cache('systask');
  94. // $key = "partnercashcache".'::'.$this->enterpriseId;
  95. // $result = $this->cache->get($key);
  96. // if(!empty($result)){
  97. // return ["code"=>-1,"msg"=>"操作频繁"];
  98. // }
  99. // $this->cache->set($key,1,10);
  100. // [$money] = UtilService::getMore([
  101. // ['money', 0, 'is_numeric', '请输入正确的提现金额'],
  102. // ], $request, true);
  103. // //缓存
  104. // $redis = \think\facade\Cache::store('redis');
  105. // $key = 'user_tixian_' . $request->user['uid'];
  106. // $bool = $redis->handler()->exists($key);
  107. // if ($bool) {
  108. // return app('json')->fail('您的操作过于频繁,请稍等再重试!');
  109. // }
  110. // $redis->set($key,1,10);//30秒缓存
  111. // $user = $request->user;
  112. // if(empty($user["openid"])){
  113. // return app('json')->fail('您还未绑定微信');
  114. // }
  115. // if(floatval($money)<=0){
  116. // return app('json')->fail('请输入正确的提现金额');
  117. // }
  118. // if(floatval($money)>$user["money"]){
  119. // return app('json')->fail('您的余额不足,无法提现');
  120. // }
  121. // if(empty($user["bank_type"]) || empty($user["bank_num"]) || empty($user["bank_name"])){
  122. // return app('json')->fail('您还未绑定提现账户');
  123. // }
  124. // if($user["bank_type"]!="alipay" && empty($user["bank_ad"])){
  125. // return app('json')->fail('您还未绑定提现开户行');
  126. // }
  127. // $sysData = (new SysModel)->where("id",1)->find();
  128. // if(floatval($user["money"])<floatval($sysData["tx_limit_money"]) || floatval($money)<floatval($sysData["tx_limit_money"])){
  129. // return app('json')->fail("满{$sysData['tx_limit_money']}元,才可提现");
  130. // }
  131. // //提现手续费
  132. // $hand_money = $sysData["tx_process_per"] > 0 ? floatval($money) * $sysData["tx_process_per"] / 100 : 0;
  133. // $hand_money = num_min_format($hand_money);
  134. // $save=[];
  135. // $save["uid"] = $user["uid"];
  136. // $save["bank_type"] = $user["bank_type"];
  137. // $save["bank_num"] = $user["bank_num"];
  138. // $save["bank_name"] = $user["bank_name"];
  139. // $save["bank_ad"] = $user["bank_ad"];
  140. // $save["money"] = floatval($money);
  141. // $save["hand_money"] = ($sysData["tx_process_max"] > 0 && $hand_money > $sysData["tx_process_max"]) ? $sysData["tx_process_max"] : $hand_money;
  142. // $save["tx_money"] = $save["money"] - $save["hand_money"];
  143. // $save["status"] = 0;
  144. // $save["time"] = time();
  145. // try{
  146. // Db::startTrans();
  147. // //插入提现申请
  148. // $tx_id = (new TxModel)->insertGetId($save);
  149. // if(empty($tx_id)){
  150. // return app('json')->fail('提交失败');
  151. // }
  152. // //更新提现账户余额并添加明细
  153. // $r= (new UserDetailModel)->txApplyMoney($user["uid"],floatval($money),$tx_id);
  154. // if(!$r){
  155. // (new TxModel)->where("id",$tx_id)->delete();
  156. // return app('json')->fail('提交失败');
  157. // }
  158. // Db::commit();
  159. // $redis->delete($key);
  160. // return app('json')->success('提交成功,等待客服处理');
  161. // } catch (DbException $db){
  162. // Db::rollback();
  163. // return app('json')->fail("订单生成失败");
  164. // }
  165. }
  166. /**
  167. * 添加上下级关系
  168. * @throws Exception
  169. */
  170. public function relationshipBusinessman()
  171. {
  172. $params = $this->request->getRawJson();
  173. if(empty($params)){
  174. parent::sendOutput('参数为空', ErrorCode::$paramError);
  175. }
  176. $data = [
  177. 'businessmanId' => getArrayItem($params, 'businessmanId'),
  178. 'source' => getArrayItem($params, 'source'),
  179. ];
  180. foreach($data as $key => $value){
  181. if(empty($value) && $value !== 0){
  182. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  183. }
  184. }
  185. $modelResult = $this->objMCommissionBusinessman->relationshipBusinessman($data);
  186. if(!$modelResult->isSuccess()){
  187. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  188. }
  189. parent::sendOutput($modelResult->getData());
  190. }
  191. /**
  192. * 分销商详情
  193. */
  194. public function getInfoBusinessman()
  195. {
  196. $where['userCenterId'] = $this->onlineUserId;
  197. $modelResult = $this->objMCommissionBusinessman->getInfoBusinessman($where);
  198. if(!$modelResult->isSuccess()){
  199. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  200. }
  201. parent::sendOutput($modelResult->getData());
  202. }
  203. /**
  204. * 查询分销商的所有下级
  205. * @throws Exception
  206. */
  207. public function getAllSub()
  208. {
  209. $params = $this->request->getRawJson();
  210. if(empty($params)){
  211. parent::sendOutput('参数为空', ErrorCode::$paramError);
  212. }
  213. $data = [
  214. 'id' => isset($params['id']) ? $params['id'] : '',
  215. 'level' => isset($params['level']) ? $params['level'] : '',
  216. 'page' => isset($params['page']) ? $params['page'] : '',
  217. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : '',
  218. ];
  219. foreach($data as $key => $value){
  220. if(empty($value) && $value !== 0){
  221. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  222. }
  223. }
  224. $pageParams = pageToOffset($params['page'],$params['pageSize']);
  225. $data['limit'] = $pageParams['limit'];
  226. $data['offset'] = $pageParams['offset'];
  227. $modelResult = $this->objMCommissionBusinessman->getAllSub($data);
  228. if(!$modelResult->isSuccess()){
  229. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  230. }
  231. $returnData = $modelResult->getData();
  232. $pageData = [
  233. 'pageIndex' => $params['page'],
  234. 'pageSize' => $params['pageSize'],
  235. 'pageTotal' => $returnData['total'],
  236. 'subTotal' => $returnData['subTotal'],
  237. 'businessmanTotal' => $returnData['businessmanTotal'],
  238. 'subBusinessmanTotal' => $returnData['subBusinessmanTotal'],
  239. ];
  240. parent::sendOutput($returnData['data'], 0, $pageData);
  241. }
  242. }