CustomerContact.Class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Jindouyun\Cache\CustomerCache;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Customer\MCustomerContact;
  15. class CustomerContact extends BaseController
  16. {
  17. private $objMCustomerContact;
  18. public function __construct($isCheckAcl = true, $isMustLogin = true)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin);
  21. $this->objMCustomerContact = new MCustomerContact($this->onlineEnterpriseId, $this->onlineUserId);
  22. }
  23. /**
  24. * 添加和编辑客户联系人管理公共字段处理方法
  25. *
  26. * @return array
  27. */
  28. public function commonFieldFilter(){
  29. $params = $this->request->getRawJson();
  30. if( empty($params) ){
  31. $this->sendOutput('参数为空', ErrorCode::$paramError );
  32. }
  33. $customerContactData = [
  34. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  35. 'name' => isset($params['name']) ? $params['name'] : '',
  36. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',
  37. ];
  38. foreach($customerContactData as $key => $value){
  39. if(empty($value) && $value !== 0){
  40. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  41. }
  42. }
  43. $customerContactData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  44. $customerContactData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  45. $customerContactData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  46. $customerContactData['address'] = isset($params['address']) ? $params['address'] : '';
  47. $customerContactData['deleteStatus']= StatusCode::$standard;
  48. $customerContactData['createTime'] = time();
  49. $customerContactData['updateTime'] = time();
  50. return $customerContactData;
  51. }
  52. /**
  53. * 添加客户联系人
  54. */
  55. public function addCustomerContact()
  56. {
  57. $customerContactData = $this->commonFieldFilter();
  58. $result = $this->objMCustomerContact->addCustomerContact($customerContactData);
  59. if($result->isSuccess()){
  60. parent::sendOutput($result->getData());
  61. }else{
  62. parent::sendOutput($result->getData(), $result->getErrorCode());
  63. }
  64. }
  65. /**
  66. * 获取指定客户联系人信息
  67. */
  68. public function getCustomerContactInfo()
  69. {
  70. $customerContactId = $this->request->param('request_id');
  71. if ( !$customerContactId ) {
  72. $this->sendOutput('参数错误', ErrorCode::$paramError );
  73. }
  74. $result = $this->objMCustomerContact->getCustomerContactInfo($customerContactId);
  75. if($result->isSuccess()){
  76. $this->sendOutput($result->getData());
  77. }else{
  78. $this->sendOutput($result->getData(), $result->getErrorCode());
  79. }
  80. }
  81. /**
  82. * 编辑客户联系人
  83. */
  84. public function editCustomerContact()
  85. {
  86. $customerContactId = $this->request->param('request_id');
  87. if(empty($customerContactId)){
  88. $this->sendOutput('参数错误', ErrorCode::$paramError);
  89. }
  90. $customerContactData = $this->commonFieldFilter();
  91. $customerContactData['id'] = $customerContactId;
  92. unset($customerContactData['createTime']);
  93. $result = $this->objMCustomerContact->editCustomerContact($customerContactData);
  94. if($result->isSuccess()){
  95. parent::sendOutput($result->getData());
  96. }else{
  97. parent::sendOutput($result->getData(), $result->getErrorCode());
  98. }
  99. }
  100. /**
  101. * 删除客户联系人
  102. */
  103. public function delCustomerContact()
  104. {
  105. $customerContactId = $this->request->param('request_id');
  106. if(!$customerContactId){
  107. $this->sendOutput('参数错误', ErrorCode::$paramError);
  108. }
  109. $result = $this->objMCustomerContact->delCustomerContact($customerContactId);
  110. if($result->isSuccess()){
  111. parent::sendOutput($result->getData());
  112. }else{
  113. parent::sendOutput($result->getData(), $result->getErrorCode());
  114. }
  115. }
  116. /**
  117. * 客户联系人启用和禁用
  118. */
  119. public function updateCustomerContactStatus()
  120. {
  121. $params['id'] = $this->request->param('request_id');
  122. $params['type'] = $this->request->param('type');
  123. if($params['type'] == 1){ //启用
  124. $params['enableStatus'] = StatusCode::$standard;
  125. }else if($params['type'] == 2){ //停用
  126. $params['enableStatus'] = StatusCode::$offline;
  127. }
  128. foreach($params as $key => $value){
  129. if(empty($value)){
  130. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  131. }
  132. }
  133. unset($params['type']);
  134. $result = $this->objMCustomerContact->updateCustomerContactStatus($params);
  135. if($result->isSuccess()){
  136. parent::sendOutput($result->getData());
  137. }else{
  138. parent::sendOutput($result->getData(), $result->getErrorCode());
  139. }
  140. }
  141. /**
  142. * 后台所有客户联系人列表
  143. */
  144. public function getAllCustomerContact()
  145. {
  146. $result = $this->objMCustomerContact->getAllCustomerContact([],'*',true);
  147. if($result->isSuccess()){
  148. parent::sendOutput($result->getData(), 0);
  149. }else{
  150. parent::sendOutput($result->getData(), $result->getErrorCode());
  151. }
  152. }
  153. }