ApiCustomer.Class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <?php
  2. /**
  3. * 获取当前登录的客户信息
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/11/20
  7. * Time: 19:24
  8. */
  9. namespace JinDouYun\Controller\Customer;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use Jindouyun\Cache\CustomerCache;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Customer\MCustomer;
  16. use JinDouYun\Model\System\MCustomerSource;
  17. use JinDouYun\Model\Goods\MGoodsCollect;
  18. use JinDouYun\Model\Customer\MCustomerDemand;
  19. use JinDouYun\Model\Customer\MCustomerVisitsLog;
  20. use JinDouYun\Model\Customer\MMemberBalanceDetail;
  21. use JinDouYun\Model\Customer\MReflectDetail;
  22. use JinDouYun\Model\Finance\MCustomerBalanceDetail;
  23. use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
  24. use Util\Common\AgentTools;
  25. class ApiCustomer extends BaseController
  26. {
  27. private $objMCustomer;
  28. private $objMCustomerSource;
  29. private $objMGoodsCollect;
  30. private $objMCustomerDemand;
  31. private $objMCustomerVisitsLog;
  32. private $objMMemberBalanceDetail;
  33. private $objMReflectDetail;
  34. private $objMCustomerBalanceDetail;
  35. private $agentTool;
  36. private $customerData;
  37. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
  38. {
  39. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  40. $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  41. $this->objMCustomerSource = new MCustomerSource($this->onlineEnterpriseId);
  42. $this->objMGoodsCollect = new MGoodsCollect($this->onlineEnterpriseId, $this->onlineUserId);
  43. $this->objMCustomerDemand = new MCustomerDemand($this->onlineEnterpriseId, $this->onlineUserId);
  44. $this->objMCustomerVisitsLog = new MCustomerVisitsLog($this->onlineEnterpriseId, $this->onlineUserId);
  45. $this->objMMemberBalanceDetail = new MMemberBalanceDetail($this->onlineEnterpriseId, $this->onlineUserId);
  46. $this->objMReflectDetail = new MReflectDetail($this->onlineEnterpriseId, $this->onlineUserId);
  47. $this->objMCustomerBalanceDetail = new MCustomerBalanceDetail($this->onlineEnterpriseId, $this->onlineUserId);
  48. $this->agentTool = new AgentTools($this->onlineEnterpriseId);
  49. // $this->customerData = $this->agentTool->getCustomerDataByUserCenterId($this->onlineUserId);
  50. }
  51. /**
  52. * 添加和编辑客户管理公共字段处理方法
  53. *
  54. * @return array
  55. */
  56. public function commonFieldFilter()
  57. {
  58. $params = $this->request->getRawJson();
  59. if (empty($params)) {
  60. $this->sendOutput('参数为空', ErrorCode::$paramError);
  61. }
  62. $customerData = [
  63. 'name' => isset($params['name']) ? $params['name'] : '',
  64. 'contact' => isset($params['contact']) ? $params['contact'] : '',
  65. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  66. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  67. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  68. ];
  69. foreach ($customerData as $key => $value) {
  70. if (empty($value) && $value !== 0) {
  71. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  72. }
  73. }
  74. $customerData['type'] = isset($params['type']) ? $params['type'] : '';
  75. $customerData['recommenderType'] = isset($params['recommenderType']) ? $params['recommenderType'] : '';
  76. $customerData['recommenderId'] = isset($params['recommenderId']) ? $params['recommenderId'] : '';
  77. $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : 0;//经度
  78. $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : 0;//纬度
  79. $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';
  80. $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
  81. $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  82. $customerData['extend'] = isset($params['extend']) ? json_encode($params['extend']) : '';
  83. $customerData['address'] = getArrayItem($params, 'address', '');
  84. $customerData['updateTime'] = time();
  85. return $customerData;
  86. }
  87. /**
  88. * 修改当前客户信息
  89. */
  90. public function editCustomerInfo()
  91. {
  92. $customerData = $this->commonFieldFilter();
  93. $customerData['userCenterId'] = $this->onlineUserId;
  94. $result = $this->objMCustomer->editCustomerInfo($customerData);
  95. if ($result->isSuccess()) {
  96. parent::sendOutput($result->getData());
  97. } else {
  98. parent::sendOutput($result->getData(), $result->getErrorCode());
  99. }
  100. }
  101. /**
  102. * 获取当前的客户信息
  103. */
  104. public function getCustomerInfo()
  105. {
  106. $customerData = $this->objMCustomer->getCustomerInfoByUserCenterId($this->onlineUserId, true);
  107. if ($customerData->isSuccess()) {
  108. $customerInfo = $customerData->getData();
  109. $agentData = $this->agentTool->getAndSetAgentData($customerInfo["id"]);
  110. $customerInfo["agentId"] = empty($agentData) ? 0 : $agentData["id"];
  111. $this->sendOutput($customerInfo);
  112. } else {
  113. $this->sendOutput($customerData->getData(), ErrorCode::$contentNotExists);
  114. }
  115. }
  116. /**
  117. * 完善资料获取客户类型
  118. */
  119. public function getCustomerSourceList()
  120. {
  121. $result = $this->objMCustomerSource->getCustomerSourceList();
  122. if ($result->isSuccess()) {
  123. $returnData = $result->getData();
  124. parent::sendOutput($returnData);
  125. } else {
  126. parent::sendOutput($result->getData(), $result->getErrorCode());
  127. }
  128. }
  129. /**
  130. * 收藏商品
  131. * @throws Exception
  132. */
  133. public function collect()
  134. {
  135. $goodsId = $this->request->param('request_id');
  136. if (!$goodsId) {
  137. $this->sendOutput('参数错误', ErrorCode::$paramError);
  138. }
  139. $result = $this->objMGoodsCollect->addGoodsCollect($goodsId);
  140. if ($result->isSuccess()) {
  141. $this->sendOutput($result->getData());
  142. }
  143. $this->sendOutput($result->getData(), $result->getErrorCode());
  144. }
  145. /**
  146. * 充值余额
  147. * @throws Exception
  148. */
  149. public function rechargeBalance()
  150. {
  151. $params = $this->request->getRawJson();
  152. $data['money'] = isset($params['money']) ? $params['money'] : '';
  153. foreach ($data as $key => $value) {
  154. if (empty($value)) {
  155. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  156. }
  157. }
  158. $data['userCenterId'] = $this->onlineUserId;
  159. $data['id'] = $this->request->get_onlineip();
  160. $result = $this->objMCustomer->rechargeBalance($data);
  161. if (!$result->isSuccess()) {
  162. parent::sendOutput($result->getData(), $result->getErrorCode());
  163. }
  164. parent::sendOutput($result->getData());
  165. }
  166. /**
  167. * 充值记录列表
  168. */
  169. public function getAllRechargeBalance()
  170. {
  171. $params = $this->request->getRawJson();
  172. if (empty($params)) {
  173. $this->sendOutput('参数为空', ErrorCode::$paramError);
  174. }
  175. $selectParams['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  176. foreach ($selectParams as $key => $value) {
  177. if (empty($value)) {
  178. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  179. }
  180. }
  181. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  182. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  183. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  184. $selectParams['limit'] = $pageParams['limit'];
  185. $selectParams['offset'] = $pageParams['offset'];
  186. $selectParams['userCenterId'] = $this->onlineUserId;
  187. $modelResult = $this->objMCustomer->getAllRechargeBalance($selectParams);
  188. if (!$modelResult->isSuccess()) {
  189. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  190. }
  191. $returnData = $modelResult->getData();
  192. $pageData = [
  193. 'pageIndex' => $params['page'],
  194. 'pageSize' => $params['pageSize'],
  195. 'pageTotal' => $returnData['total'],
  196. ];
  197. parent::sendOutput($returnData['data'], 0, $pageData);
  198. }
  199. /**
  200. * 添加客户需求
  201. */
  202. public function addCustomerdemand()
  203. {
  204. $params = $this->request->getRawJson();
  205. if (empty($params)) {
  206. $this->sendOutput('参数为空', ErrorCode::$paramError);
  207. }
  208. $demandData = [
  209. 'enterpriseId' => $this->onlineEnterpriseId,
  210. 'customerId' => getArrayItem($params, 'customerId'),
  211. 'demand' => getArrayItem($params, 'demand'),
  212. ];
  213. $demandData['updateTime'] = time();
  214. $result = $this->objMCustomerDemand->addCustomerdemand($demandData);
  215. if ($result->isSuccess()) {
  216. parent::sendOutput($result->getData());
  217. } else {
  218. parent::sendOutput($result->getData(), $result->getErrorCode());
  219. }
  220. }
  221. /**
  222. * 添加客户访问记录
  223. */
  224. public function addCustomerVisitsLog()
  225. {
  226. $params = $this->request->getRawJson();
  227. if (empty($params)) {
  228. $this->sendOutput('参数为空', ErrorCode::$paramError);
  229. }
  230. $visitsLogData = [
  231. 'usercenterid' => getArrayItem($params, 'usercenterid'),
  232. 'customerid' => getArrayItem($params, 'customerid'),
  233. 'shopid' => getArrayItem($params, 'shopid'),
  234. 'goodsid' => getArrayItem($params, 'goodsid'),
  235. ];
  236. $visitsLogData['updateTime'] = time();
  237. $result = $this->objMCustomerVisitsLog->addCustomerVisitsLog($visitsLogData);
  238. if ($result->isSuccess()) {
  239. parent::sendOutput($result->getData());
  240. } else {
  241. parent::sendOutput($result->getData(), $result->getErrorCode());
  242. }
  243. }
  244. /**
  245. * 添加余额支付密码
  246. */
  247. public function addpayPassword()
  248. {
  249. $params = $this->request->getRawJson();
  250. if (empty($params)) {
  251. $this->sendOutput('参数为空', ErrorCode::$paramError);
  252. }
  253. $payPasswordData = [
  254. 'enterpriseId' => $this->onlineEnterpriseId,
  255. 'id' => getArrayItem($params, 'id'),
  256. 'payPassword' => getArrayItem($params, 'payPassword'),
  257. ];
  258. foreach ($payPasswordData as $key => $value) {
  259. if (empty($value)) {
  260. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  261. }
  262. }
  263. $payPasswordData['updateTime'] = time();
  264. //密码格式化;
  265. $payPasswordData['payPassword'] = password_hash($payPasswordData['payPassword'], PASSWORD_DEFAULT);
  266. $result = $this->objMCustomer->addpayPassword($payPasswordData);
  267. if ($result->isSuccess()) {
  268. parent::sendOutput($result->getData());
  269. } else {
  270. parent::sendOutput($result->getData(), $result->getErrorCode());
  271. }
  272. }
  273. /**
  274. * 修改余额支付密码
  275. */
  276. public function updatePayPassword()
  277. {
  278. $params = $this->request->getRawJson();
  279. if (!$params) {
  280. $this->sendOutput('参数错误', ErrorCode::$paramError);
  281. }
  282. $updatePayPasswordData = [
  283. 'enterpriseId' => $this->onlineEnterpriseId,
  284. 'id' => getArrayItem($params, 'id'),
  285. 'payPassword' => trim(getArrayItem($params, 'payPassword')),
  286. ];
  287. foreach ($updatePayPasswordData as $key => $value) {
  288. if (empty($value)) {
  289. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  290. }
  291. }
  292. $updatePayPasswordData['updateTime'] = time();
  293. $updatePayPasswordData['payPassword'] = password_hash($updatePayPasswordData['payPassword'], PASSWORD_DEFAULT);
  294. $result = $this->objMCustomer->updatePayPassword($updatePayPasswordData);
  295. if ($result->isSuccess()) {
  296. parent::sendOutput($result->getData());
  297. } else {
  298. parent::sendOutput($result->getData(), $result->getErrorCode());
  299. }
  300. }
  301. /**
  302. * 校验余额支付密码
  303. */
  304. public function checkPayPassword()
  305. {
  306. $params = $this->request->getRawJson();
  307. if (!$params) {
  308. $this->sendOutput('参数错误', ErrorCode::$paramError);
  309. }
  310. $checkPayPasswordData = [
  311. 'enterpriseId' => $this->onlineEnterpriseId,
  312. 'id' => getArrayItem($params, 'id'),
  313. 'payPassword' => trim(getArrayItem($params, 'payPassword')),
  314. ];
  315. foreach ($checkPayPasswordData as $key => $value) {
  316. if (empty($value)) {
  317. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  318. }
  319. }
  320. $result = $this->objMCustomer->checkPayPassword($checkPayPasswordData);
  321. if ($result->isSuccess()) {
  322. parent::sendOutput($result->getData());
  323. } else {
  324. parent::sendOutput($result->getData(), $result->getErrorCode());
  325. }
  326. }
  327. /**
  328. * 获取所有的明细
  329. */
  330. public function getAllMemberBalanceDetail()
  331. {
  332. $params = $this->request->getRawJson();
  333. if (empty($params)) {
  334. $this->sendOutput('参数为空', ErrorCode::$paramError);
  335. }
  336. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  337. $params['limit'] = $pageParams['limit'];
  338. $params['offset'] = $pageParams['offset'];
  339. $params['userCenterId'] = $this->onlineUserId;
  340. $params['customerId'] = getArrayItem($params, 'customerId', '');
  341. $returnData = $this->objMMemberBalanceDetail->getAllMemberBalanceDetail($params);
  342. if ($returnData->isSuccess()) {
  343. $returnData = $returnData->getData();
  344. $pageData = [
  345. 'pageIndex' => $params['page'],
  346. 'pageSize' => $params['pageSize'],
  347. 'pageTotal' => $returnData['total'],
  348. ];
  349. parent::sendOutput($returnData['data'], 0, $pageData);
  350. } else {
  351. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  352. }
  353. }
  354. /**
  355. * 申请提现
  356. */
  357. public function addReflectDetail()
  358. {
  359. $params = $this->request->getRawJson();
  360. if (empty($params)) {
  361. $this->sendOutput('参数为空', ErrorCode::$paramError);
  362. }
  363. $ReflectDetailDate = [
  364. 'customerId' => getArrayItem($params, 'customerId', ''),
  365. 'userCenterId' => $this->onlineUserId,
  366. 'reflectType' => getArrayItem($params, 'reflectType', ''),
  367. 'money' => getArrayItem($params, 'money', ''),
  368. 'reflectInfo' => getArrayItem($params, 'reflectInfo', []),
  369. 'reflectStatus' => getArrayItem($params, 'reflectStatus', 4),
  370. 'auditStatus' => getArrayItem($params, 'auditStatus', StatusCode::$auditStatus['auditing']),
  371. ];
  372. foreach ($ReflectDetailDate as $key => $value) {
  373. if (empty($value) && $value !== 0) {
  374. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  375. }
  376. }
  377. $ReflectDetailDate['reflectInfo'] = json_encode($ReflectDetailDate['reflectInfo']);
  378. $ReflectDetailDate['remark'] = getArrayItem($params, 'remark', '');
  379. $ReflectDetailDate['createTime'] = time();
  380. $result = $this->objMReflectDetail->addReflectDetail($ReflectDetailDate);
  381. if ($result->isSuccess()) {
  382. parent::sendOutput($result->getData());
  383. } else {
  384. parent::sendOutput($result->getData(), $result->getErrorCode());
  385. }
  386. }
  387. /**
  388. * 所有提现记录
  389. */
  390. public function getAllReflectDetail()
  391. {
  392. $params = $this->request->getRawJson();
  393. if (empty($params)) {
  394. $this->sendOutput('参数为空', ErrorCode::$paramError);
  395. }
  396. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  397. $params['limit'] = $pageParams['limit'];
  398. $params['offset'] = $pageParams['offset'];
  399. $params['start'] = getArrayItem($params, 'start', "");
  400. $params['end'] = getArrayItem($params, 'end', "");
  401. $params['customerId'] = getArrayItem($params, 'customerId', '');
  402. $returnData = $this->objMReflectDetail->getAllReflectDetail($params);
  403. if ($returnData->isSuccess()) {
  404. $returnData = $returnData->getData();
  405. $pageData = [
  406. 'pageIndex' => $params['page'],
  407. 'pageSize' => $params['pageSize'],
  408. 'pageTotal' => $returnData['total'],
  409. ];
  410. parent::sendOutput($returnData['data'], 0, $pageData);
  411. } else {
  412. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  413. }
  414. }
  415. /**
  416. * 积分流水
  417. */
  418. public function getAllCustomerIntegralDesc()
  419. {
  420. $params = $this->request->getRawJson();
  421. $page = isset($params['page']) ? $params['page'] : 1;
  422. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  423. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  424. $data['limit'] = $pageParams['limit'];
  425. $data['offset'] = $pageParams['offset'];
  426. $data['customerId'] = $params['customerId'];
  427. if (empty($params['customerId'])) {
  428. parent::sendOutput('customerId参数为空', ErrorCode::$paramError);
  429. }
  430. if (isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])) {
  431. $data['createTime'] = [
  432. 'star' => $params['star'],
  433. 'end' => $params['end']
  434. ];
  435. }
  436. $modelResult = $this->objMCustomer->getAllCustomerIntegralDesc($data);
  437. if (!$modelResult->isSuccess()) {
  438. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  439. }
  440. $returnData = $modelResult->getData();
  441. $pageData = [
  442. 'pageIndex' => $page,
  443. 'pageSize' => $pageSize,
  444. 'pageTotal' => $returnData['total'],
  445. ];
  446. parent::sendOutput($returnData['data'], 0, $pageData);
  447. }
  448. /**
  449. * 小程序充值
  450. */
  451. public function rechargeMemberBalance()
  452. {
  453. $params = $this->request->getRawJson();
  454. if (empty($params)) {
  455. $this->sendOutput('参数为空', ErrorCode::$paramError);
  456. }
  457. //记录流水
  458. $memberBalanceDetailData = [
  459. 'customerId' => $params['customerId'],
  460. 'type' => StatusCode::$standard,
  461. 'userCenterId' => $this->onlineUserId,
  462. 'money' => $params['money'],
  463. 'purpose' => '充值',
  464. 'orderIds' => '',
  465. 'remark' => '充值' . $params['money'],
  466. 'financeType' => '会员余额充值',
  467. ];
  468. foreach ($memberBalanceDetailData as $k => $v) {
  469. if (in_array($k, ['customerId', 'money', 'purpose']) && empty($v)) {
  470. $this->sendOutput('请输入' . $k, ErrorCode::$paramError);
  471. }
  472. }
  473. $result = $this->objMMemberBalanceDetail->addMemberBalanceDetail($memberBalanceDetailData);
  474. if ($result->isSuccess()) {
  475. parent::sendOutput($result->getData());
  476. } else {
  477. parent::sendOutput($result->getData(), $result->getErrorCode());
  478. }
  479. }
  480. /**
  481. * 小程序客户余额明细列表
  482. */
  483. public function getAllCustomerBalanceDetail()
  484. {
  485. $params = $this->request->getRawJson();
  486. if (empty($params)) {
  487. $this->sendOutput('参数为空', ErrorCode::$paramError);
  488. }
  489. $selectParams = [
  490. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  491. ];
  492. foreach ($selectParams as $key => $value) {
  493. if (empty($value) && $value !== 0) {
  494. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  495. }
  496. }
  497. $selectParams['start'] = !empty($params['start']) ? $params['start'] : 0;
  498. $selectParams['end'] = !empty($params['end']) ? strtotime(date('Y-m-d', $params['end']) . '23:59:59') : time();
  499. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  500. $selectParams['limit'] = $pageParams['limit'];
  501. $selectParams['offset'] = $pageParams['offset'];
  502. $result = $this->objMCustomerBalanceDetail->getAllCustomerBalanceDetail($selectParams);
  503. if ($result->isSuccess()) {
  504. $returnData = $result->getData();
  505. $pageData = [
  506. 'pageIndex' => $params['page'],
  507. 'pageSize' => $params['pageSize'],
  508. 'pageTotal' => $returnData['total'],
  509. 'openingBalance' => $returnData['openingBalance'],
  510. 'endingBalance' => $returnData['endingBalance'],
  511. 'shouldReceiveTotal' => $returnData['shouldReceiveTotal'],
  512. 'actualReceiveTotal' => $returnData['actualReceiveTotal'],
  513. ];
  514. parent::sendOutput($returnData['data'], 0, $pageData);
  515. } else {
  516. parent::sendOutput($result->getData(), $result->getErrorCode());
  517. }
  518. }
  519. }