Customer.Class.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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\Customer;
  10. use JinDouYun\Dao\Department\DDepartment;
  11. use JinDouYun\Dao\Department\DStaff;
  12. use JinDouYun\Dao\Shop\DShop;
  13. use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
  14. use JinDouYun\Dao\System\DCustomerSource;
  15. use Mall\Framework\Core\ErrorCode;
  16. use Mall\Framework\Core\StatusCode;
  17. use JinDouYun\Controller\BaseController;
  18. use Jindouyun\Cache\CustomerCache;
  19. use JinDouYun\Model\Customer\MCustomer;
  20. use JinDouYun\Model\Order\MOrder;
  21. use JinDouYun\Model\Customer\MReflectDetail;
  22. use JinDouYun\Model\Customer\MMemberBalanceDetail;
  23. use JinDouYun\Dao\Customer\DCustomer;
  24. use Util\Common\PartnerTools;
  25. class Customer extends BaseController
  26. {
  27. /**
  28. * @var MCustomer
  29. */
  30. private $objMReflectDetail;
  31. private $objMMemberBalanceDetail;
  32. private $objMCustomer;
  33. private $dbCustomer;
  34. private $partnerTool;
  35. //private $objTempSaveCache;
  36. public function __construct($isCheckAcl = true, $isMustLogin = true)
  37. {
  38. parent::__construct($isCheckAcl, $isMustLogin);
  39. $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  40. $this->objMReflectDetail = new MReflectDetail($this->onlineEnterpriseId,$this->onlineUserId);
  41. $this->objMMemberBalanceDetail = new MMemberBalanceDetail($this->onlineEnterpriseId,$this->onlineUserId);
  42. //$this->objTempSaveCache = new TempSaveCache();
  43. //用户表
  44. $this->dbCustomer = new DCustomer('default');
  45. $customerTableName = $this->dbCustomer->getTableName($this->dbCustomer->get_Table(), $this->onlineEnterpriseId, 1);
  46. $this->dbCustomer->setTable($customerTableName);
  47. $this->partnerTool = new PartnerTools($this->onlineEnterpriseId);
  48. }
  49. /**
  50. * 添加和编辑客户管理公共字段处理方法
  51. *
  52. * @return array
  53. */
  54. public function commonFieldFilter(){
  55. $params = $this->request->getRawJson();
  56. if( empty($params) ){
  57. $this->sendOutput('参数为空', ErrorCode::$paramError );
  58. }
  59. $customerData = [
  60. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',//账号
  61. 'name' => isset($params['name']) ? $params['name'] : '',
  62. 'type' => isset($params['type']) ? $params['type'] : '',//客户类型
  63. ];
  64. //非暂存则验空
  65. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  66. foreach($customerData as $key => $value){
  67. if(empty($value) && $value !== 0){
  68. $this->sendOutput($key.'参数错误', ErrorCode::$paramError);
  69. }
  70. }
  71. }
  72. $customerData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;//启用状态
  73. $customerData['contact'] = isset($params['contact']) ? $params['contact'] : '';
  74. $customerData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  75. $customerData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  76. $customerData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  77. $customerData['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  78. $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : '';
  79. $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : '';
  80. $customerData['tempSave']= isset($params['tempSave']) ? $params['tempSave'] : false;
  81. $customerData['password'] = isset($params['password']) ? $params['password'] : '';//密码
  82. $customerData['address'] = isset($params['address']) ? $params['address'] : '';
  83. $customerData['managerMobile'] = isset($params['managerMobile']) ? $params['managerMobile'] : '';
  84. $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';//客户头像
  85. // $customerData['sortingId'] = isset($params['sortingId']) ? $params['sortingId'] : '';
  86. $customerData['departmentId'] = isset($params['departmentId']) ? $params['departmentId'] : '';
  87. $customerData['salesManId'] = isset($params['salesManId']) ? $params['salesManId'] : '';
  88. $customerData['salesManCode'] = isset($params['salesManCode']) ? $params['salesManCode'] : '';
  89. $customerData['salesManName'] = isset($params['salesManName']) ? $params['salesManName'] : '';
  90. $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
  91. $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  92. $customerData['deleteStatus']= StatusCode::$standard;
  93. $customerData['status']= isset($params['status']) ? $params['status'] : '';
  94. $customerData['area'] = isset($params['area']) ? $params['area'] : [];
  95. $customerData['shopName'] = isset($params['shopName']) ? $params['shopName'] : '';
  96. $customerData['reservoirId'] = isset($params['reservoirId']) ? $params['reservoirId'] : '';
  97. (isset($params['extend']) && !empty($params['extend'])) && $customerData['extend'] = json_encode($params['extend']);
  98. $customerData['memberBalance'] = getArrayItem($params, 'memberBalance','');
  99. $customerData['recommenderType'] = getArrayItem($params,'recommenderType','');
  100. $customerData['recommenderId'] =getArrayItem($params,'recommenderId','');
  101. $customerData['createTime'] = time();
  102. $customerData['updateTime'] = time();
  103. //联系人信息
  104. $customerData['contact'] = getArrayItem($params,'contact', []);
  105. return $customerData;
  106. }
  107. /**
  108. * 添加客户
  109. * @throws \Exception
  110. */
  111. public function addCustomer()
  112. {
  113. $customerData = $this->commonFieldFilter();
  114. if ($customerData['tempSave']) {
  115. //$this->objTempSaveCache->saveCustomer($this->onlineEnterpriseId, $this->onlineUserId, $customerData);
  116. parent::sendOutput('暂存成功');
  117. }
  118. unset($customerData['tempSave']);
  119. unset($customerData['area']);
  120. unset($customerData['shopName']);
  121. $result = $this->objMCustomer ->addCustomer($customerData);
  122. if($result->isSuccess()){
  123. //删除暂存数据
  124. //$this->objTempSaveCache->delCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  125. parent::sendOutput($result->getData());
  126. }else{
  127. parent::sendOutput($result->getData(), $result->getErrorCode());
  128. }
  129. }
  130. /**
  131. * 获取暂存信息
  132. */
  133. public function getTempData()
  134. {
  135. //$result = $this->objTempSaveCache->getCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  136. $this->sendOutput('');
  137. }
  138. /**
  139. * 获取指定客户信息
  140. * @throws \Exception
  141. */
  142. public function getCustomerInfo()
  143. {
  144. $customerId = $this->request->param('request_id');
  145. if ( !$customerId ) {
  146. $this->sendOutput('参数错误', ErrorCode::$paramError );
  147. }
  148. // 直接从缓存层返回
  149. $objCustomerCache = new CustomerCache();
  150. $customerData = $objCustomerCache->getCustomerData($this->onlineEnterpriseId, $customerId);
  151. if( !empty($customerData) ){
  152. $this->sendOutput($customerData);
  153. }
  154. $result = $this->objMCustomer->getCustomerInfo($customerId);
  155. if($result->isSuccess()){
  156. $objCustomerCache->cacheCustomerData($this->onlineEnterpriseId, $customerId, $result->getData());
  157. $this->sendOutput($result->getData());
  158. }else{
  159. $this->sendOutput($result->getData(), $result->getErrorCode());
  160. }
  161. }
  162. /**
  163. * 编辑客户
  164. * @throws \Exception
  165. */
  166. public function editCustomer()
  167. {
  168. $customerId = $this->request->param('request_id');
  169. if(empty($customerId)){
  170. $this->sendOutput('参数错误', ErrorCode::$paramError);
  171. }
  172. $customerData = $this->commonFieldFilter();
  173. $customerData['id'] = $customerId;
  174. unset($customerData['createTime']);
  175. unset($customerData['status']);
  176. unset($customerData['tempSave']);
  177. unset($customerData['area']);
  178. unset($customerData['shopName']);
  179. $result = $this->objMCustomer->editCustomer($customerData);
  180. if($result->isSuccess()){
  181. parent::sendOutput($result->getData());
  182. }else{
  183. parent::sendOutput($result->getData(), $result->getErrorCode());
  184. }
  185. }
  186. /**
  187. * 更新用户分销推广信息
  188. */
  189. public function updateUserNewPartner(){
  190. $params = $this->request->getRawJson();
  191. $postData = [
  192. 'id' => isset($params['id']) ? (int)$params['id'] : 0,
  193. 'parentId' => isset($params['parentId']) ? (int)$params['parentId'] : 0,//上级id
  194. 'isPartner' => isset($params['isPartner']) ? (int)$params['isPartner'] : 0,//是否合伙人
  195. ];
  196. if(empty($postData["id"])){
  197. parent::sendOutput('参数错误', ErrorCode::$paramError);
  198. }
  199. $postData["isPartner"] = $postData["isPartner"]===1?1:0;
  200. $userData = $this->dbCustomer->get($postData["id"]);
  201. if(empty($userData)){
  202. parent::sendOutput('用户不存在', ErrorCode::$paramError);
  203. }
  204. $save=["isPartner"=>$postData["isPartner"]];
  205. if($userData["parentId"]==0 && $postData["parentId"]!=0){
  206. $this->partnerTool->setPushCustomer($postData["parentId"], $userData["id"]);
  207. }
  208. $this->dbCustomer->update($save,["id"=>$userData["id"]]);
  209. parent::sendOutput("操作完成");
  210. }
  211. /**
  212. * 后台批量分配部门及业务员
  213. */
  214. public function batchEditCustomer()
  215. {
  216. $params = $this->request->getRawJson();
  217. $data = [
  218. 'ids' => isset($params['ids']) ? $params['ids'] : [],
  219. 'departmentId' => isset($params['departmentId']) ? $params['departmentId'] : 0,//部门id
  220. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : 0,//业务员id
  221. ];
  222. foreach ($data as $key => $val){
  223. if (empty($val)){
  224. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  225. }
  226. }
  227. $result = $this->objMCustomer->batchEditCustomer($data);
  228. if(!$result->isSuccess()){
  229. $objCustomerCache = new CustomerCache();
  230. foreach ($data['ids'] as $key => $value){
  231. $objCustomerCache->delCustomerData($this->onlineEnterpriseId, $value);
  232. }
  233. parent::sendOutput($result->getData(), $result->getErrorCode());
  234. }
  235. parent::sendOutput($result->getData());
  236. }
  237. /**
  238. * 删除客户
  239. * @throws \Exception
  240. */
  241. public function delCustomer()
  242. {
  243. $userCenterIds = $this->request->getRawJson();
  244. if(!$userCenterIds){
  245. $this->sendOutput('参数错误', ErrorCode::$paramError);
  246. }
  247. $result = $this->objMCustomer->delCustomer($userCenterIds);
  248. if($result->isSuccess()){
  249. parent::sendOutput($result->getData());
  250. }else{
  251. parent::sendOutput($result->getData(), $result->getErrorCode());
  252. }
  253. }
  254. /**
  255. * 客户启用和禁用
  256. * @throws \Exception
  257. */
  258. public function updateCustomerStatus()
  259. {
  260. $params = $this->request->getRawJson();
  261. if( empty($params['id']) && empty($params['enableStatus'])){
  262. $this->sendOutput('参数为空', ErrorCode::$paramError );
  263. }
  264. $result = $this->objMCustomer->updateCustomerStatus($params);
  265. if($result->isSuccess()){
  266. parent::sendOutput($result->getData());
  267. }else{
  268. parent::sendOutput($result->getData(), $result->getErrorCode());
  269. }
  270. }
  271. /**
  272. * 客户审核通过和审核拒绝
  273. * @throws \Exception
  274. */
  275. public function updateCustomerCheckStatus()
  276. {
  277. $params = $this->request->getRawJson();
  278. if( empty($params['id']) && empty($params['status'])){
  279. $this->sendOutput('参数为空', ErrorCode::$paramError );
  280. }
  281. if($params['status'] == StatusCode::$auditStatus['auditNotPass'] && !isset($params['reason'])) {
  282. $this->sendOutput('请输入审核拒绝的原因', ErrorCode::$paramError );
  283. }
  284. $params['reason'] = isset($params['reason']) ? $params['reason'] : '';
  285. $result = $this->objMCustomer->updateCustomerCheckStatus($params);
  286. if($result->isSuccess()){
  287. parent::sendOutput($result->getData());
  288. }else{
  289. parent::sendOutput($result->getData(), $result->getErrorCode());
  290. }
  291. }
  292. /**
  293. * 后台所有客户列表
  294. * @throws \Exception
  295. */
  296. public function getAllCustomer()
  297. {
  298. $params = $this->request->getRawJson();
  299. if( empty($params) ){
  300. $this->sendOutput('参数为空', ErrorCode::$paramError );
  301. }
  302. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  303. $condition = [
  304. 'status' => isset($params['status']) ? $params['status'] : 2,
  305. 'enableStatus' => getArrayItem($params, 'enableStatus', 0),
  306. 'keyword' => getArrayItem($params, 'keyword', ''),
  307. 'salesManId' => getArrayItem($params, 'salesManId', 0),
  308. 'shopId' => getArrayItem($params, 'shopId', 0),
  309. 'cityCode' => getArrayItem($params, 'cityCode', 0),
  310. 'districtCode' => getArrayItem($params, 'districtCode', 0),
  311. 'provinceCode' => getArrayItem($params, 'provinceCode', 0),
  312. 'offset' => $pageParams['offset'],
  313. 'limit' => $pageParams['limit'],
  314. ];
  315. $result = $this->objMCustomer->getAllCustomer($condition);
  316. if($result->isSuccess()){
  317. $returnData = $result->getData();
  318. $pageData = [
  319. 'pageIndex' => $params['page'],
  320. 'pageSize' => $params['pageSize'],
  321. 'pageTotal' => $returnData['total'],
  322. ];
  323. parent::sendOutput($returnData['data'], 0, $pageData);
  324. }else{
  325. parent::sendOutput($result->getData(), $result->getErrorCode());
  326. }
  327. }
  328. /**
  329. * 添加客户标签
  330. * @throws \Exception
  331. */
  332. public function addCustomerTag() {
  333. $params = $this->request->getRawJson();
  334. if( empty($params['id']) && empty($params['tag']) ){
  335. $this->sendOutput('参数为空', ErrorCode::$paramError );
  336. }
  337. $result = $this->objMCustomer->addCustomerTag($params);
  338. if($result->isSuccess()){
  339. parent::sendOutput($result->getData());
  340. }else{
  341. parent::sendOutput($result->getData(), $result->getErrorCode());
  342. }
  343. }
  344. /**
  345. * 删除客户标签
  346. * @throws \Exception
  347. */
  348. public function delCustomerTag() {
  349. $params = $this->request->getRawJson();
  350. if( empty($params['id']) && empty($params['tag']) ){
  351. $this->sendOutput('参数为空', ErrorCode::$paramError );
  352. }
  353. $result = $this->objMCustomer->delCustomerTag($params);
  354. if($result->isSuccess()){
  355. parent::sendOutput($result->getData());
  356. }else{
  357. parent::sendOutput($result->getData(), $result->getErrorCode());
  358. }
  359. }
  360. /**
  361. * 搜索
  362. */
  363. public function search() {
  364. $params = $this->request->getRawJson();
  365. if( empty($params) ){
  366. $this->sendOutput('参数为空', ErrorCode::$paramError );
  367. }
  368. $selectParams = [
  369. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  370. 'type' => isset($params['type']) ? $params['type'] : '',
  371. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  372. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  373. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  374. 'status' => isset($params['status']) ? $params['status'] : '',
  375. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  376. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  377. 'departmentId' => isset($params['departmentId']) ? $params['departmentId'] : '',
  378. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',
  379. 'start' => isset($params['start']) ? $params['start'] : '',
  380. 'end' => isset($params['end']) ? $params['end'] : ''
  381. ];
  382. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  383. $selectParams['limit'] = $pageParams['limit'];
  384. $selectParams['offset'] = $pageParams['offset'];
  385. $result = $this->objMCustomer->search($selectParams);
  386. if($result->isSuccess()){
  387. $returnData = $result->getData();
  388. $pageData = [
  389. 'pageIndex' => $params['page'],
  390. 'pageSize' => $params['pageSize'],
  391. 'pageTotal' => $returnData['total'],
  392. ];
  393. parent::sendOutput($returnData['data'], 0, $pageData);
  394. }else{
  395. parent::sendOutput($result->getData(), $result->getErrorCode());
  396. }
  397. }
  398. /**
  399. * 客户查询
  400. * @throws \Exception
  401. */
  402. public function query() {
  403. $params = $this->request->getRawJson();
  404. if( empty($params) ){
  405. $this->sendOutput('参数为空', ErrorCode::$paramError );
  406. }
  407. $selectParams = [
  408. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//关键字:客户姓名/手机号/负责人电话
  409. 'tag' => isset($params['tag']) ? $params['tag'] : '',//标签
  410. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',//区域
  411. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  412. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  413. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//客户启用状态
  414. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',//所属商铺
  415. 'source' => isset($params['source']) ? $params['source'] : '',//来源
  416. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',//业务员
  417. 'birthday_start' => isset($params['birthday_start']) ? $params['birthday_start'] : '',//客户生日 开始
  418. 'birthday_end' => isset($params['birthday_end']) ? $params['birthday_end'] : ''//客户生日 结束
  419. ];
  420. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  421. $selectParams['limit'] = $pageParams['limit'];
  422. $selectParams['offset'] = $pageParams['offset'];
  423. $result = $this->objMCustomer->query($selectParams);
  424. if($result->isSuccess()){
  425. $returnData = $result->getData();
  426. $pageData = [
  427. 'pageIndex' => $params['page'],
  428. 'pageSize' => $params['pageSize'],
  429. 'pageTotal' => $returnData['total'],
  430. 'customerTotalNum' => $this->objMCustomer->getCustomerTotalNum(),
  431. 'newCustomerNum' => $this->objMCustomer->getNewCustomerNum(),
  432. 'interestCustomerNum' =>$this->objMCustomer->getInterestCustomerNum(),
  433. ];
  434. parent::sendOutput($returnData['data'], 0, $pageData);
  435. }else{
  436. parent::sendOutput($result->getData(), $result->getErrorCode());
  437. }
  438. }
  439. /**
  440. * 根据code获取客户的经纬度信息
  441. */
  442. public function getCustomerLocation() {
  443. $params = $this->request->getRawJson();
  444. $code = isset($params['code']) ? $params['code'] : '';
  445. $result = $this->objMCustomer->getCustomerLocation($code);
  446. if($result->isSuccess()){
  447. $returnData = $result->getData();
  448. parent::sendOutput($returnData);
  449. }else{
  450. parent::sendOutput($result->getData(), $result->getErrorCode());
  451. }
  452. }
  453. /**
  454. * 导出方法
  455. * @throws \Exception
  456. */
  457. public function export()
  458. {
  459. $params = $this->request->getRawJson();
  460. $selectParams = [
  461. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  462. 'type' => isset($params['type']) ? $params['type'] : '',
  463. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  464. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  465. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  466. 'status' => isset($params['status']) ? $params['status'] : '',
  467. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  468. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  469. 'departmentId' => isset($params['departmentId']) ? $params['departmentId'] : '',
  470. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',
  471. 'start' => isset($params['start']) ? $params['start'] : '',
  472. 'end' => isset($params['end']) ? $params['end'] : ''
  473. ];
  474. $selectParams['limit'] = null;
  475. $selectParams['offset'] = null;
  476. $result = $this->objMCustomer->getAllCustomer($selectParams);
  477. if($result->isSuccess() == false){
  478. parent::sendOutput($result->getData(), $result->getErrorCode());
  479. }
  480. $returnData = $result->getData();
  481. $data = $returnData['data'];
  482. //导出到本地
  483. header ( "Content-type:application/vnd.ms-excel" );
  484. header ( "Content-Disposition:filename=客户列表.csv" );
  485. header ('Cache-Control: max-age=0');
  486. $fp = fopen('php://output', 'a');
  487. $head = ['客户名称','联系人','登录账号','客户类型','商铺','销售部门','业务员','账号状态','备注']; //定义标题
  488. foreach ($head as $i => $v) {
  489. $head[$i] = mb_convert_encoding($v, 'GBK', 'utf-8'); //将中文标题转换编码,否则乱码
  490. }
  491. fputcsv($fp, $head);
  492. $limit = 10000;
  493. $num = 0; //计数器
  494. foreach ( $data as $v ) { //循环数据
  495. $num++;
  496. if($num == $limit){
  497. ob_flush(); //释放内存
  498. flush();
  499. }
  500. $rows=[
  501. 'name'=>$v['name'],
  502. 'contactName'=>empty($v['contact']) ? '' : $v['contact'][0]['name'],
  503. 'mobile' => $v['mobile'],
  504. 'customerType' => $v['customerType'],
  505. 'shopName' => $v['shopName'],
  506. 'departmentName' => $v['departmentName'],
  507. 'salesManName' => $v['salesManName'],
  508. 'enableStatus' => ($v['enableStatus'] == StatusCode::$standard) ? "启用" : "禁用",
  509. 'remark' => $v['remark'],
  510. ];
  511. foreach ( $rows as $kk => $vv){
  512. $rs[$kk] = mb_convert_encoding($vv, 'GBK', 'utf-8'); //转译编码
  513. }
  514. fputcsv($fp, $rs);
  515. $rows = [];
  516. }
  517. }
  518. public function formatCustomer()
  519. {
  520. $result = $this->objMCustomer->formatCustomer();
  521. if(!$result->isSuccess()){
  522. parent::sendOutput($result->getData(), $result->getErrorCode());
  523. }
  524. parent::sendOutput($result->getData());
  525. }
  526. /**
  527. * 充值记录列表
  528. */
  529. public function getAllRechargeBalance()
  530. {
  531. $params = $this->request->getRawJson();
  532. if(empty($params)){
  533. $this->sendOutput('参数为空', ErrorCode::$paramError);
  534. }
  535. $selectParams['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  536. foreach($selectParams as $key => $value){
  537. if(empty($value)){
  538. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  539. }
  540. }
  541. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  542. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  543. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  544. $selectParams['limit'] = $pageParams['limit'];
  545. $selectParams['offset'] = $pageParams['offset'];
  546. if(isset($params['customerId'])){
  547. $selectParams['customerId'] = $params['customerId'];
  548. }
  549. if(isset($params['userCenterId'])){
  550. $selectParams['userCenterId'] = $params['userCenterId'];
  551. }
  552. $modelResult = $this->objMCustomer->getAllRechargeBalance($selectParams);
  553. if(!$modelResult->isSuccess()){
  554. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  555. }
  556. $returnData = $modelResult->getData();
  557. $pageData = [
  558. 'pageIndex' => $params['page'],
  559. 'pageSize' => $params['pageSize'],
  560. 'pageTotal' => $returnData['total'],
  561. ];
  562. parent::sendOutput($returnData['data'], 0, $pageData);
  563. }
  564. /**
  565. * 首字母搜索客户
  566. */
  567. public function initialsSearch()
  568. {
  569. $params = $this->request->getRawJson();
  570. $data['condition'] = isset($params['condition']) ? trim($params['condition']) : '';
  571. $modelResult = $this->objMCustomer->initialsSearch($data);
  572. if(!$modelResult->isSuccess()){
  573. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  574. }
  575. parent::sendOutput($modelResult->getData());
  576. }
  577. /**
  578. * 初始化客户首字母
  579. */
  580. public function initialsCustomer()
  581. {
  582. $modelResult = $this->objMCustomer->initialsCustomer();
  583. if(!$modelResult->isSuccess()){
  584. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  585. }
  586. parent::sendOutput($modelResult->getData());
  587. }
  588. /**
  589. * Doc: (des="查询客户商品购买记录")
  590. * User: XMing
  591. * Date: 2021/3/10
  592. * Time: 10:54 上午
  593. */
  594. public function searchCustomerBuyLog()
  595. {
  596. $params = $this->request->getRawJson();
  597. $page = isset($params['page']) ? $params['page'] : 1;
  598. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  599. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  600. $params['limit'] = $pageParams['limit'];
  601. $params['offset'] = $pageParams['offset'];
  602. $export = isset($params['export']) ? $params['export'] : 0;
  603. $modelResult = $this->objMCustomer->searchCustomerBuyLog($params,$export);
  604. if(!$modelResult->isSuccess()){
  605. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  606. }
  607. $returnData = $modelResult->getData();
  608. $pageData = [
  609. 'pageIndex' => $page,
  610. 'pageSize' => $pageSize,
  611. 'pageTotal' => $returnData['total'],
  612. ];
  613. parent::sendOutput($returnData['data'], 0, $pageData);
  614. }
  615. /**
  616. * Doc: (des="销售排行")
  617. * User: XMing
  618. * Date: 2021/3/15
  619. * Time: 10:06 上午
  620. * @throws \Exception
  621. */
  622. public function salesManRank()
  623. {
  624. $params = $this->request->getRawJson();
  625. $page = isset($params['page']) ? $params['page'] : 1;
  626. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  627. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  628. $params['limit'] = $pageParams['limit'];
  629. $params['offset'] = $pageParams['offset'];
  630. $params['startTime'] = getArrayItem($params, 'startTime', strtotime(date('y-m-d 00:00:00'))) ;
  631. $params['endTime'] = getArrayItem($params, 'endTime', strtotime(date('y-m-d 23:59:59')));
  632. $params['orderStatus'] = getArrayItem($params, 'orderStatus',[4,5]);
  633. $objMOrder = new MOrder($this->onlineUserId,$this->onlineEnterpriseId);
  634. $export = isset($params['export']) ? $params['export'] : 0;
  635. $modelResult = $objMOrder->salesManRank($params,$export);
  636. if(!$modelResult->isSuccess()){
  637. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  638. }
  639. $returnData = $modelResult->getData();
  640. $pageData = [
  641. 'pageIndex' => $page,
  642. 'pageSize' => $pageSize,
  643. 'pageTotal' => $returnData['total'],
  644. ];
  645. parent::sendOutput($returnData['data'], 0, $pageData);
  646. }
  647. /**
  648. * 积分流水
  649. */
  650. public function getAllCustomerIntegralDesc()
  651. {
  652. $params = $this->request->getRawJson();
  653. $page = isset($params['page']) ? $params['page'] : 1;
  654. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  655. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  656. $data['limit'] = $pageParams['limit'];
  657. $data['offset'] = $pageParams['offset'];
  658. $data['customerId'] = isset($params['customerId']) ? $params['customerId'] : '';
  659. if(empty($data['customerId'])){
  660. parent::sendOutput('customerId参数为空', ErrorCode::$paramError);
  661. }
  662. if(isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])){
  663. $data['createTime'] = [
  664. 'star' => $params['star'],
  665. 'end' => $params['end']
  666. ];
  667. }
  668. $modelResult = $this->objMCustomer->getAllCustomerIntegralDesc($data);
  669. if(!$modelResult->isSuccess()){
  670. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  671. }
  672. $returnData = $modelResult->getData();
  673. $pageData = [
  674. 'pageIndex' => $page,
  675. 'pageSize' => $pageSize,
  676. 'pageTotal' => $returnData['total'],
  677. ];
  678. parent::sendOutput($returnData['data'], 0, $pageData);
  679. }
  680. /**
  681. * 修改积分
  682. * @throws \Exception
  683. */
  684. public function updateCustomerIntegral()
  685. {
  686. $params = $this->request->getRawJson();
  687. $data = [
  688. 'integral' => isset($params['integral']) ? $params['integral'] : '',
  689. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  690. 'type' => isset($params['type']) ? $params['type'] : '',
  691. ];
  692. foreach($data as $key => $value){
  693. if(empty($value)){
  694. parent::sendOutput($key.'参数为空', ErrorCode::$paramError);
  695. }
  696. }
  697. $data['desc'] = isset($params['desc']) ? $params['desc'] : '';
  698. if($this->shopId){
  699. $data['shopId'] = $this->shopId;
  700. }
  701. $result = $this->objMCustomer->updateCustomerIntegral($data);
  702. if(!$result->isSuccess()){
  703. $objCustomerCache = new CustomerCache();
  704. $objCustomerCache->delCustomerData($this->onlineEnterpriseId, $params['customerId']);
  705. parent::sendOutput($result->getData(), $result->getErrorCode());
  706. }
  707. parent::sendOutput($result->getData());
  708. }
  709. /**
  710. * 新注册未下单统计
  711. */
  712. public function noOrderCustomer()
  713. {
  714. $params = $this->request->getRawJson();
  715. if(!$params){
  716. parent::sendOutput('请求参数为空', ErrorCode::$paramError);
  717. }
  718. $data = [
  719. 'intervalDay' => getArrayItem($params, 'intervalDay', 10),
  720. 'customerName' => getArrayItem($params, 'customerName'),
  721. 'salesManId' => getArrayItem($params, 'salesManId'),
  722. 'provinceCode' => getArrayItem($params, 'provinceCode'),
  723. 'cityCode' => getArrayItem($params, 'cityCode'),
  724. 'districtCode' => getArrayItem($params, 'districtCode'),
  725. ];
  726. $page = getArrayItem($params, 'page', 1);
  727. $pageSize = getArrayItem($params, 'pageSize', 10);
  728. $pageParams = pageToOffset($page, $pageSize);
  729. $data['limit'] = $pageParams['limit'];
  730. $data['offset'] = $pageParams['offset'];
  731. $returnData = $this->objMCustomer->noOrderCustomer($data);
  732. if(!$returnData->isSuccess()){
  733. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  734. }
  735. $returnData = $returnData->getData();
  736. $pageData = [
  737. 'pageIndex' => $page,
  738. 'pageSize' => $pageSize,
  739. 'pageTotal' => $returnData['total'],
  740. ];
  741. parent::sendOutput($returnData['data'], 0, $pageData);
  742. }
  743. /**
  744. * 距离最近一次未下单统计
  745. */
  746. public function intervalNoOrderCustomer()
  747. {
  748. $params = $this->request->getRawJson();
  749. if(!$params){
  750. parent::sendOutput('请求参数为空', ErrorCode::$paramError);
  751. }
  752. $data = [
  753. 'intervalDay' => getArrayItem($params, 'intervalDay', 10),
  754. 'customerName' => getArrayItem($params, 'customerName'),
  755. 'salesManId' => getArrayItem($params, 'salesManId'),
  756. 'provinceCode' => getArrayItem($params, 'provinceCode'),
  757. 'cityCode' => getArrayItem($params, 'cityCode'),
  758. 'districtCode' => getArrayItem($params, 'districtCode'),
  759. ];
  760. $page = getArrayItem($params, 'page', 1);
  761. $pageSize = getArrayItem($params, 'pageSize', 10);
  762. $pageParams = pageToOffset($page, $pageSize);
  763. $data['limit'] = $pageParams['limit'];
  764. $data['offset'] = $pageParams['offset'];
  765. $returnData = $this->objMCustomer->intervalNoOrderCustomer($data);
  766. if(!$returnData->isSuccess()){
  767. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  768. }
  769. $returnData = $returnData->getData();
  770. $pageData = [
  771. 'pageIndex' => $page,
  772. 'pageSize' => $pageSize,
  773. 'pageTotal' => $returnData['total'],
  774. ];
  775. parent::sendOutput($returnData['data'], 0, $pageData);
  776. }
  777. /**
  778. * 拉新统计
  779. */
  780. public function recommenderStatic()
  781. {
  782. $params = $this->request->getRawJson();
  783. if(!$params){
  784. parent::sendOutput('请求参数为空', ErrorCode::$paramError);
  785. }
  786. $data = [
  787. 'startTime' => getArrayItem($params, 'startTime', 0),
  788. 'endTime' => getArrayItem($params, 'endTime', 0),
  789. 'customerId' => getArrayItem($params, 'customerId', 0),
  790. 'staffId' => getArrayItem($params, 'staffId', 0),
  791. ];
  792. $page = getArrayItem($params, 'page', 1);
  793. $pageSize = getArrayItem($params, 'pageSize', 10);
  794. $pageParams = pageToOffset($page, $pageSize);
  795. $data['limit'] = $pageParams['limit'];
  796. $data['offset'] = $pageParams['offset'];
  797. $returnData = $this->objMCustomer->recommenderStatic($data);
  798. if(!$returnData->isSuccess()){
  799. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  800. }
  801. $returnData = $returnData->getData();
  802. $pageData = [
  803. 'pageIndex' => $page,
  804. 'pageSize' => $pageSize,
  805. 'pageTotal' => $returnData['total'],
  806. ];
  807. parent::sendOutput($returnData['data'], 0, $pageData);
  808. }
  809. //审核,打款公共方法
  810. public function updateReflectDetail()
  811. {
  812. $params = $this->request->getRawJson();
  813. if (empty($params['id']) || empty($params['createTime'])) {
  814. $this->sendOutput('参数为空', ErrorCode::$paramError);
  815. }
  816. $result = $this->objMReflectDetail->updateReflectDetail($params);
  817. if ($result->isSuccess()) {
  818. parent::sendOutput($result->getData());
  819. } else {
  820. parent::sendOutput($result->getData(), $result->getErrorCode());
  821. }
  822. }
  823. /**
  824. * 所有提现记录
  825. */
  826. public function getAllReflectDetail()
  827. {
  828. $params = $this->request->getRawJson();
  829. if (empty($params)) {
  830. $this->sendOutput('参数为空', ErrorCode::$paramError);
  831. }
  832. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  833. $params['limit'] = $pageParams['limit'];
  834. $params['offset'] = $pageParams['offset'];
  835. $params['start'] = getArrayItem($params,'start',"");
  836. $params['end'] = getArrayItem($params,'end',"");
  837. $params['customerId'] = getArrayItem($params,'customerId', '');
  838. $params['reflectStatus'] = getArrayItem($params,'reflectStatus', '');
  839. $params['auditStatus'] = getArrayItem($params,'auditStatus', '');
  840. $params['reflectType'] = getArrayItem($params,'reflectType', '');//提现类型
  841. $returnData = $this->objMReflectDetail->getAllReflectDetail($params);
  842. if ($returnData->isSuccess()) {
  843. $returnData = $returnData->getData();
  844. $pageData = [
  845. 'pageIndex' => $params['page'],
  846. 'pageSize' => $params['pageSize'],
  847. 'pageTotal' => $returnData['total'],
  848. ];
  849. parent::sendOutput($returnData['data'], 0, $pageData);
  850. } else {
  851. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  852. }
  853. }
  854. /**
  855. * 后台充值
  856. */
  857. public function rechargeMemberBalance()
  858. {
  859. $params = $this->request->getRawJson();
  860. if (empty($params)) {
  861. $this->sendOutput('参数为空', ErrorCode::$paramError);
  862. }
  863. //记录流水
  864. $memberBalanceDetailData = [
  865. 'customerId' => $params['customerId'],
  866. 'type' => $params['type'],
  867. 'userCenterId' => $this->onlineUserId,
  868. 'money' =>$params['money'],
  869. 'purpose' => isset($params['purpose']) ? $params['purpose']: 0,
  870. 'orderIds' =>'',
  871. 'remark' => '充值'.$params['money'],
  872. 'financeType' => '会员余额充值',
  873. 'accountId' => isset($params['accountId']) ? $params['accountId']: 0,
  874. 'accountName' => isset($params['accountName']) ? $params['accountName']: '',
  875. 'accountNumber' => isset($params['accountNumber']) ? $params['accountNumber']: '',
  876. 'explain' => isset($params['explain']) ? $params['explain']: '',
  877. ];
  878. foreach ($memberBalanceDetailData as $k =>$v) {//,'accountId','accountName','accountNumber'
  879. if(in_array($k, ['customerId','money','purpose']) && empty($v)) {
  880. $this->sendOutput('请输入'.$k, ErrorCode::$paramError);
  881. }
  882. }
  883. $result = $this->objMMemberBalanceDetail->addMemberBalanceDetail($memberBalanceDetailData,$isbackstage=true);
  884. if (!$result->isSuccess()) {
  885. parent::sendOutput($result->getData(), $result->getErrorCode());
  886. }
  887. parent::sendOutput($result->getData());
  888. }
  889. /**
  890. * 接收导入客户数据参数
  891. * @throws \Exception
  892. */
  893. public function getCustomerBasicImportParams()
  894. {
  895. //获取数据文件
  896. $params = $this->request->getRawJson();
  897. //企业id
  898. $enterpriseId = $this->onlineEnterpriseId;
  899. //引用dao
  900. $objDSysAreaChina = new DSysAreaChina(); //省市区dao
  901. $objDShop = new DShop();//商铺dao
  902. $objDShop->setTable('qianniao_shop_1' );
  903. $objDDepartment = new DDepartment();//销售部门dao
  904. $objDDepartment->setTable('qianniao_department_' . $enterpriseId);
  905. $objDDStaff = new DStaff();//员工表
  906. $objDDStaff->setTable('qianniao_staff_' . $enterpriseId);
  907. //获取数据
  908. $postArray = [];
  909. foreach ($params as $value) {
  910. $customerArray = $value;
  911. //客户信息
  912. $name = isset($customerArray['name']) ? trim($customerArray['name']) : '';//客户名称
  913. $mobile = isset($customerArray['mobile']) ? trim($customerArray['mobile']) : '';//登录账号
  914. $contacts = isset($customerArray['contacts']) ? trim($customerArray['contacts']) : '';//联系人
  915. $nameMobile = isset($customerArray['nameMobile']) ? trim($customerArray['nameMobile']) : 4;//联系人电话
  916. $birthday = isset($customerArray['birthday']) ? trim($customerArray['birthday']) : '';//客户生日
  917. $remark = isset($customerArray['remark']) ? trim($customerArray['remark']) : '';//客户备注
  918. $customerType = isset($customerArray['type']) ? trim($customerArray['type']) : '';//客户类型
  919. //省市区
  920. $provinceName = isset($customerArray['provinceName']) ? trim($customerArray['provinceName']) : '';//省名称
  921. $cityName = isset($customerArray['cityName']) ? trim($customerArray['cityName']) : '';//市名称
  922. $areaName = isset($customerArray['areaName']) ? trim($customerArray['areaName']) : '';//区名称
  923. $address = isset($customerArray['address']) ? trim($customerArray['address']) : '';//详细地址
  924. $shopName = isset($customerArray['shopName']) ? trim($customerArray['shopName']) : '';//商铺名称
  925. $departmentId = isset($customerArray['departmentId']) ? trim($customerArray['departmentId']) : '';//销售部门id
  926. $salesManId = isset($customerArray['salesManId']) ? trim($customerArray['salesManId']) : '';//业务员Id
  927. $salesManCode = createCode(StatusCode::$code['staff']['prefix'],$salesManId, StatusCode::$code['staff']['length']);
  928. if (empty($name)) {
  929. continue;
  930. }
  931. // //业务员
  932. // $salesManId = 0;
  933. // $salesManCode ='';
  934. // if(!empty($salesManName)){
  935. // $dbResult = $objDDStaff->get(['staffName'=> $salesManName]);
  936. // if($dbResult !== false){
  937. // $salesManId = $dbResult['id'];
  938. // $salesManCode = createCode(StatusCode::$code['staff']['prefix'],$salesManId, StatusCode::$code['staff']['length']);
  939. //
  940. // }
  941. // }
  942. //商铺
  943. $shopId = 0;
  944. if(!empty($shopName)){
  945. $dbResult = $objDShop->get(['name'=>$shopName]);
  946. if($dbResult !== false){
  947. $shopId = $dbResult['id'];
  948. }
  949. }
  950. //销售部门
  951. // $departmentId = 0;
  952. // if(!empty($departmentName)){
  953. // $dbResult = $objDDepartment->get(['departmentName'=>$departmentName]);
  954. // if($dbResult !== false){
  955. // $departmentId = $dbResult['id'];
  956. // }
  957. // }
  958. //省市区
  959. $provinceCode ='';
  960. $cityCode = '';
  961. $areaCode = '';
  962. if(!empty($provinceName)){
  963. //省编码
  964. $dbResult = $objDSysAreaChina->get(['name'=>$provinceName]);
  965. if($dbResult !== false){
  966. $provinceCode = $dbResult['code'];
  967. //市编码
  968. $dbResult = $objDSysAreaChina->get(['name'=>$cityName,'pcode'=>$provinceCode]);
  969. if($dbResult !== false){
  970. $cityCode = $dbResult['code'];
  971. //区编码
  972. $dbResult = $objDSysAreaChina->get(['name'=>$areaName,'pcode'=>$cityCode]);
  973. if($dbResult !== false){
  974. $areaCode = $dbResult['code'];
  975. }
  976. }
  977. }
  978. }
  979. $postData = array (
  980. 'tempSave' => '',
  981. 'latitude' => '',
  982. 'longitude' => '',
  983. 'password' => '',
  984. 'area' => '',
  985. 'mobile' => $mobile,
  986. 'enableStatus' => 5,
  987. 'name' => $name,
  988. 'code' => '',
  989. 'type' => $customerType,
  990. 'provinceCode' => $provinceCode,
  991. 'cityCode' => $cityCode,
  992. 'districtCode' => $areaCode,
  993. 'address' => $address,
  994. 'managerMobile' => '',
  995. 'shopId' => $shopId,
  996. 'departmentId' => $departmentId,
  997. 'salesManId' => $salesManId,
  998. 'salesManCode' => $salesManCode,
  999. 'salesManName' => '',
  1000. 'birthday' => $birthday,
  1001. 'remark' => $remark,
  1002. 'reservoirId' => $customerType,
  1003. 'recommenderType' => '',
  1004. 'recommenderId' => '',
  1005. 'extend' =>
  1006. array (
  1007. 'license' => '',
  1008. ),
  1009. 'contact' =>
  1010. array (
  1011. 'area' => '',
  1012. 'name' => $contacts,
  1013. 'mobile' => $nameMobile,
  1014. 'provinceCode' => $provinceCode,
  1015. 'cityCode' => $cityCode,
  1016. 'districtCode' => $areaCode,
  1017. 'address' => $address,
  1018. ),
  1019. );
  1020. $postArray[] = $postData;
  1021. }
  1022. return $postArray;
  1023. }
  1024. /**
  1025. * 导入客户资料
  1026. * @throws \Exception
  1027. */
  1028. public function customerImport()
  1029. {
  1030. //把页面传来的参数对应到符合的字段中全部传递过来;
  1031. $paramsArray = self::getCustomerBasicImportParams();
  1032. if (empty($paramsArray)) {
  1033. $this->sendOutput('参数为空', ErrorCode::$paramError);
  1034. }
  1035. $customerBasic = [];
  1036. foreach ($paramsArray as $params) {
  1037. $customerData = [
  1038. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',//账号
  1039. 'name' => isset($params['name']) ? $params['name'] : '',
  1040. 'type' => isset($params['type']) ? $params['type'] : '',//客户类型
  1041. ];
  1042. //非暂存则验空
  1043. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  1044. foreach ($customerData as $key => $value) {
  1045. if (empty($value) && $value !== 0) {
  1046. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  1047. }
  1048. }
  1049. }
  1050. $customerData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;//启用状态
  1051. $customerData['contact'] = isset($params['contact']) ? $params['contact'] : '';
  1052. $customerData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  1053. $customerData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  1054. $customerData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  1055. $customerData['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  1056. $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : '';
  1057. $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : '';
  1058. $customerData['tempSave'] = isset($params['tempSave']) ? $params['tempSave'] : false;
  1059. $customerData['password'] = isset($params['password']) ? $params['password'] : '';//密码
  1060. $customerData['address'] = isset($params['address']) ? $params['address'] : '';
  1061. $customerData['managerMobile'] = isset($params['managerMobile']) ? $params['managerMobile'] : '';
  1062. $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';//客户头像
  1063. // $customerData['sortingId'] = isset($params['sortingId']) ? $params['sortingId'] : '';
  1064. $customerData['departmentId'] = isset($params['departmentId']) ? $params['departmentId'] : '';
  1065. $customerData['salesManId'] = isset($params['salesManId']) ? $params['salesManId'] : '';
  1066. $customerData['salesManCode'] = isset($params['salesManCode']) ? $params['salesManCode'] : '';
  1067. $customerData['salesManName'] = isset($params['salesManName']) ? $params['salesManName'] : '';
  1068. $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
  1069. $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  1070. $customerData['deleteStatus'] = StatusCode::$standard;
  1071. $customerData['status'] = isset($params['status']) ? $params['status'] : '';
  1072. $customerData['area'] = isset($params['area']) ? $params['area'] : [];
  1073. $customerData['shopName'] = isset($params['shopName']) ? $params['shopName'] : '';
  1074. $customerData['reservoirId'] = isset($params['reservoirId']) ? $params['reservoirId'] : '';
  1075. (isset($params['extend']) && !empty($params['extend'])) && $customerData['extend'] = json_encode($params['extend']);
  1076. $customerData['memberBalance'] = getArrayItem($params, 'memberBalance', '');
  1077. $customerData['recommenderType'] = getArrayItem($params, 'recommenderType', '');
  1078. $customerData['recommenderId'] = getArrayItem($params, 'recommenderId', '');
  1079. $customerData['createTime'] = time();
  1080. $customerData['updateTime'] = time();
  1081. //联系人信息
  1082. $customerData['contact'] = getArrayItem($params, 'contact', []);
  1083. $customerBasic[] = $customerData;
  1084. }
  1085. unset($customerData);
  1086. $total = 0;
  1087. $true = 0;
  1088. $false = 0;
  1089. $exportError = date('Ymd_H:i:s').'.txt';
  1090. foreach ($customerBasic as $key => $customerData){
  1091. if ($customerData['tempSave']) {
  1092. parent::sendOutput('暂存成功');
  1093. }
  1094. unset($customerData['tempSave']);
  1095. unset($customerData['area']);
  1096. unset($customerData['shopName']);
  1097. $result = $this->objMCustomer ->addCustomer($customerData);
  1098. if(!$result->isSuccess()){
  1099. if(!is_dir(UPLOAD_FILE_PATH.'/exportError/')){
  1100. mkdir(UPLOAD_FILE_PATH.'/exportError/',0777,true);
  1101. }
  1102. $a = $key+1;
  1103. file_put_contents(UPLOAD_FILE_PATH.'/exportError/'.$exportError,'第 '. $a .'行导入失败,原因'.var_export($result->getData().$result->getErrorCode(),true).PHP_EOL,FILE_APPEND);
  1104. $false++;
  1105. } else {
  1106. $true++;
  1107. }
  1108. $total++;
  1109. }
  1110. $returnData = [
  1111. 'successMsg' => '共'.$total.'条客户数据,成功'.$true.'条客户数据,失败'.$false.'条客户数据',
  1112. 'errorNum' => $false,
  1113. 'url' => URL_UPLOAD.'exportError/'.$exportError,
  1114. ];
  1115. parent::sendOutput($returnData);
  1116. }
  1117. /**
  1118. * 客户分布
  1119. */
  1120. public function getCustomerDistributed()
  1121. {
  1122. $returnData = $this->objMCustomer->getCustomerDistributed();
  1123. if(!$returnData->isSuccess()){
  1124. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  1125. }
  1126. parent::sendOutput($returnData->getData());
  1127. }
  1128. /**
  1129. * 批量设置客户类型
  1130. */
  1131. public function setCustomerType()
  1132. {
  1133. $params = $this->request->getRawJson();
  1134. if (empty($params)) {
  1135. $this->sendOutput('参数为空', ErrorCode::$paramError);
  1136. }
  1137. $params['customerIds'] = getArrayItem($params,'customerIds',[]);
  1138. $params['type'] = getArrayItem($params,'type',0);
  1139. $result = $this->objMCustomer->setCustomerType($params);
  1140. if($result->isSuccess()){
  1141. parent::sendOutput($result->getData());
  1142. }else{
  1143. parent::sendOutput($result->getData(), $result->getErrorCode());
  1144. }
  1145. }
  1146. }