CustomerCommunication.Class.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /**
  3. * 客户沟通记录Controller
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2021/02/23
  7. * Time: 13:00
  8. */
  9. namespace JinDouYun\Controller\Customer;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Customer\MCustomerCommunication;
  15. class CustomerCommunication extends BaseController
  16. {
  17. private $objMCustomerCommunication;
  18. public function __construct($isCheckAcl = false, $isMustLogin = true)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin);
  21. $this->objMCustomerCommunication = new MCustomerCommunication($this->onlineEnterpriseId,$this->onlineUserId);
  22. }
  23. /**
  24. * 获取参数
  25. * @return array
  26. */
  27. public function commonFieldFilter()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. $this->sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $data = [
  34. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  35. 'staffId' => isset($params['staffId']) ? $params['staffId'] : '',
  36. 'content' => isset($params['content']) ? $params['content'] : '',
  37. ];
  38. //必填项
  39. foreach ($data as $key => $value) {
  40. if (empty($value) && $value !== 0) {
  41. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  42. }
  43. }
  44. //选填项
  45. $data['time'] = isset($params['time']) && !empty($params['time']) ? $params['time'] : time();
  46. $data['location'] = isset($params['location']) && !empty($params['location']) ? $params['location'] : '';
  47. $data['picture'] = isset($params['picture']) && !empty($params['picture']) ? $params['picture'] : '';
  48. return $data;
  49. }
  50. /**
  51. * 客户沟通记录添加
  52. */
  53. public function addCustomerCommunication()
  54. {
  55. $data = $this->commonFieldFilter();
  56. $result = $this->objMCustomerCommunication->addCustomerCommunication($data);
  57. if ($result->isSuccess()) {
  58. parent::sendOutput($result->getData());
  59. } else {
  60. parent::sendOutput($result->getData(), $result->getErrorCode());
  61. }
  62. }
  63. /**
  64. * 客户沟通记录删除
  65. * @throws Exception
  66. */
  67. public function delCustomerCommunication()
  68. {
  69. $id = $this->request->param('request_id');
  70. if (empty($id)) {
  71. $this->sendOutput('参数为空', ErrorCode::$paramError);
  72. }
  73. $result = $this->objMCustomerCommunication->delCustomerCommunication($id);
  74. if ($result->isSuccess()) {
  75. parent::sendOutput($result->getData());
  76. } else {
  77. parent::sendOutput($result->getData(), $result->getErrorCode());
  78. }
  79. }
  80. /**
  81. * 客户沟通记录修改
  82. */
  83. public function updateCustomerCommunication()
  84. {
  85. $id = $this->request->param('request_id');
  86. if (empty($id)) {
  87. $this->sendOutput('id参数为空', ErrorCode::$paramError);
  88. }
  89. $data = $this->commonFieldFilter();
  90. $result = $this->objMCustomerCommunication->updateCustomerCommunication($data, $id);
  91. if ($result->isSuccess()) {
  92. parent::sendOutput($result->getData());
  93. } else {
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. }
  97. /**
  98. * 客户沟通记录列表
  99. */
  100. public function getAllCustomerCommunication()
  101. {
  102. $params = $this->request->getRawJson();
  103. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  104. $selectParams['limit'] = $pageParams['limit'];
  105. $selectParams['offset'] = $pageParams['offset'];
  106. if(isset($params['customerId']) && !empty($params['customerId'])){
  107. $selectParams['customerId'] = $params['customerId'];
  108. }
  109. if(isset($params['staffId']) && !empty($params['staffId'])){
  110. $selectParams['staffId'] = $params['staffId'];
  111. }
  112. if(isset($params['start']) && !empty($params['start'])){
  113. $selectParams['start'] = $params['start'];
  114. }
  115. if(isset($params['end']) && !empty($params['end'])){
  116. $selectParams['end'] = $params['end'];
  117. }
  118. $result = $this->objMCustomerCommunication->getAllCustomerCommunication($selectParams);
  119. if ($result->isSuccess()) {
  120. $returnData = $result->getData();
  121. $pageData = [
  122. 'pageIndex' => $params['page'],
  123. 'pageSize' => $params['pageSize'],
  124. 'pageTotal' => $returnData['total'],
  125. ];
  126. parent::sendOutput($returnData['data'], 0, $pageData);
  127. } else {
  128. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  129. }
  130. }
  131. /**
  132. * 客户沟通记录详情
  133. */
  134. public function getCustomerCommunication()
  135. {
  136. $id = $this->request->param('request_id');
  137. if (empty($id)) {
  138. $this->sendOutput('参数为空', ErrorCode::$paramError);
  139. }
  140. $result = $this->objMCustomerCommunication->getCustomerCommunication(['id' => $id]);
  141. if ($result->isSuccess()) {
  142. parent::sendOutput($result->getData());
  143. } else {
  144. parent::sendOutput($result->getData(), $result->getErrorCode());
  145. }
  146. }
  147. /**
  148. * 客户拜访报表
  149. */
  150. public function getCustomerCallOnReportForm()
  151. {
  152. $params = $this->request->getRawJson();
  153. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  154. $selectParams['limit'] = $pageParams['limit'];
  155. $selectParams['offset'] = $pageParams['offset'];
  156. $selectParams['departmentId'] = isset($params['departmentId']) ? $params['departmentId'] :'';
  157. $selectParams['start'] = isset($params['start']) ? $params['start'] :'';
  158. $selectParams['end'] = isset($params['end']) ? $params['end'] :'';
  159. $result = $this->objMCustomerCommunication->getCustomerCallOnReportForm($selectParams);
  160. if ($result->isSuccess()) {
  161. $returnData = $result->getData();
  162. $pageData = [
  163. 'pageIndex' => $params['page'],
  164. 'pageSize' => $params['pageSize'],
  165. 'pageTotal' => $returnData['total'],
  166. ];
  167. parent::sendOutput($returnData['data'], 0, $pageData);
  168. } else {
  169. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  170. }
  171. }
  172. /**
  173. * 客户拜访记录详情
  174. */
  175. public function getCustomerVisitInfo()
  176. {
  177. $params = $this->request->getRawJson();
  178. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  179. $selectParams['limit'] = $pageParams['limit'];
  180. $selectParams['offset'] = $pageParams['offset'];
  181. $selectParams['staffId'] = getArrayItem($params,'staffId');
  182. $result = $this->objMCustomerCommunication->getCustomerVisitInfo($selectParams);
  183. if ($result->isSuccess()) {
  184. $returnData = $result->getData();
  185. $pageData = [
  186. 'pageIndex' => $params['page'],
  187. 'pageSize' => $params['pageSize'],
  188. 'pageTotal' => $returnData['total'],
  189. ];
  190. parent::sendOutput($returnData['data'], 0, $pageData);
  191. } else {
  192. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  193. }
  194. }
  195. /**
  196. * 未拜访客户统计列表
  197. */
  198. public function getCustomerNoVisit()
  199. {
  200. $params = $this->request->getRawJson();
  201. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  202. $selectParams['limit'] = $pageParams['limit'];
  203. $selectParams['offset'] = $pageParams['offset'];
  204. $selectParams['days'] = getArrayItem($params,'intervalDay',0);
  205. $selectParams['customerName'] = getArrayItem($params,'customerName');//客户id
  206. $selectParams['staffId'] = getArrayItem($params,'staffId');//员工id
  207. $selectParams['province'] = getArrayItem($params,'province');
  208. $selectParams['city'] = getArrayItem($params,'city');
  209. $selectParams['district'] = getArrayItem($params,'district');
  210. $result = $this->objMCustomerCommunication->getCustomerNoVisit($selectParams);
  211. if ($result->isSuccess()) {
  212. $returnData = $result->getData();
  213. $pageData = [
  214. 'pageIndex' => $params['page'],
  215. 'pageSize' => $params['pageSize'],
  216. 'pageTotal' => $returnData['total'],
  217. ];
  218. parent::sendOutput($returnData['data'], 0, $pageData);
  219. } else {
  220. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  221. }
  222. }
  223. }