123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576 |
- <?php
- /**
- * 获取当前登录的客户信息
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/11/20
- * Time: 19:24
- */
- namespace JinDouYun\Controller\Customer;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Jindouyun\Cache\CustomerCache;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Customer\MCustomer;
- use JinDouYun\Model\System\MCustomerSource;
- use JinDouYun\Model\Goods\MGoodsCollect;
- use JinDouYun\Model\Customer\MCustomerDemand;
- use JinDouYun\Model\Customer\MCustomerVisitsLog;
- use JinDouYun\Model\Customer\MMemberBalanceDetail;
- use JinDouYun\Model\Customer\MReflectDetail;
- use JinDouYun\Model\Finance\MCustomerBalanceDetail;
- use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
- use Util\Common\AgentTools;
- class ApiCustomer extends BaseController
- {
- private $objMCustomer;
- private $objMCustomerSource;
- private $objMGoodsCollect;
- private $objMCustomerDemand;
- private $objMCustomerVisitsLog;
- private $objMMemberBalanceDetail;
- private $objMReflectDetail;
- private $objMCustomerBalanceDetail;
- private $agentTool;
- private $customerData;
- public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
- $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMCustomerSource = new MCustomerSource($this->onlineEnterpriseId);
- $this->objMGoodsCollect = new MGoodsCollect($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMCustomerDemand = new MCustomerDemand($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMCustomerVisitsLog = new MCustomerVisitsLog($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMMemberBalanceDetail = new MMemberBalanceDetail($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMReflectDetail = new MReflectDetail($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMCustomerBalanceDetail = new MCustomerBalanceDetail($this->onlineEnterpriseId, $this->onlineUserId);
-
-
- $this->agentTool = new AgentTools($this->onlineEnterpriseId);
- // $this->customerData = $this->agentTool->getCustomerDataByUserCenterId($this->onlineUserId);
- }
- /**
- * 添加和编辑客户管理公共字段处理方法
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $customerData = [
- 'name' => isset($params['name']) ? $params['name'] : '',
- 'contact' => isset($params['contact']) ? $params['contact'] : '',
- 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
- 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
- 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
- ];
- foreach ($customerData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $customerData['type'] = isset($params['type']) ? $params['type'] : '';
- $customerData['recommenderType'] = isset($params['recommenderType']) ? $params['recommenderType'] : '';
- $customerData['recommenderId'] = isset($params['recommenderId']) ? $params['recommenderId'] : '';
- $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : 0;//经度
- $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : 0;//纬度
- $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';
- $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
- $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
- $customerData['extend'] = isset($params['extend']) ? json_encode($params['extend']) : '';
- $customerData['address'] = getArrayItem($params, 'address', '');
- $customerData['updateTime'] = time();
- return $customerData;
- }
- /**
- * 修改当前客户信息
- */
- public function editCustomerInfo()
- {
- $customerData = $this->commonFieldFilter();
- $customerData['userCenterId'] = $this->onlineUserId;
- $result = $this->objMCustomer->editCustomerInfo($customerData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取当前的客户信息
- */
- public function getCustomerInfo()
- {
- $customerData = $this->objMCustomer->getCustomerInfoByUserCenterId($this->onlineUserId, true);
- if ($customerData->isSuccess()) {
- $customerInfo = $customerData->getData();
-
- $agentData = $this->agentTool->getAndSetAgentData($customerInfo["id"]);
- $customerInfo["agentId"] = empty($agentData) ? 0 : $agentData["id"];
- $this->sendOutput($customerInfo);
- } else {
- $this->sendOutput($customerData->getData(), ErrorCode::$contentNotExists);
- }
- }
- /**
- * 完善资料获取客户类型
- */
- public function getCustomerSourceList()
- {
- $result = $this->objMCustomerSource->getCustomerSourceList();
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- parent::sendOutput($returnData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 收藏商品
- * @throws Exception
- */
- public function collect()
- {
- $goodsId = $this->request->param('request_id');
- if (!$goodsId) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMGoodsCollect->addGoodsCollect($goodsId);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- }
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 充值余额
- * @throws Exception
- */
- public function rechargeBalance()
- {
- $params = $this->request->getRawJson();
- $data['money'] = isset($params['money']) ? $params['money'] : '';
- foreach ($data as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['userCenterId'] = $this->onlineUserId;
- $data['id'] = $this->request->get_onlineip();
- $result = $this->objMCustomer->rechargeBalance($data);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 充值记录列表
- */
- public function getAllRechargeBalance()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
- foreach ($selectParams as $key => $value) {
- if (empty($value)) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $params['page'] = isset($params['page']) ? $params['page'] : 1;
- $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
- $pageParams = pageToOffset($params['page'], $params['pageSize']);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['userCenterId'] = $this->onlineUserId;
- $modelResult = $this->objMCustomer->getAllRechargeBalance($selectParams);
- if (!$modelResult->isSuccess()) {
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- $returnData = $modelResult->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * 添加客户需求
- */
- public function addCustomerdemand()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $demandData = [
- 'enterpriseId' => $this->onlineEnterpriseId,
- 'customerId' => getArrayItem($params, 'customerId'),
- 'demand' => getArrayItem($params, 'demand'),
- ];
- $demandData['updateTime'] = time();
- $result = $this->objMCustomerDemand->addCustomerdemand($demandData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 添加客户访问记录
- */
- public function addCustomerVisitsLog()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $visitsLogData = [
- 'usercenterid' => getArrayItem($params, 'usercenterid'),
- 'customerid' => getArrayItem($params, 'customerid'),
- 'shopid' => getArrayItem($params, 'shopid'),
- 'goodsid' => getArrayItem($params, 'goodsid'),
- ];
- $visitsLogData['updateTime'] = time();
- $result = $this->objMCustomerVisitsLog->addCustomerVisitsLog($visitsLogData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 添加余额支付密码
- */
- public function addpayPassword()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $payPasswordData = [
- 'enterpriseId' => $this->onlineEnterpriseId,
- 'id' => getArrayItem($params, 'id'),
- 'payPassword' => getArrayItem($params, 'payPassword'),
- ];
- foreach ($payPasswordData as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $payPasswordData['updateTime'] = time();
- //密码格式化;
- $payPasswordData['payPassword'] = password_hash($payPasswordData['payPassword'], PASSWORD_DEFAULT);
- $result = $this->objMCustomer->addpayPassword($payPasswordData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 修改余额支付密码
- */
- public function updatePayPassword()
- {
- $params = $this->request->getRawJson();
- if (!$params) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $updatePayPasswordData = [
- 'enterpriseId' => $this->onlineEnterpriseId,
- 'id' => getArrayItem($params, 'id'),
- 'payPassword' => trim(getArrayItem($params, 'payPassword')),
- ];
- foreach ($updatePayPasswordData as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $updatePayPasswordData['updateTime'] = time();
- $updatePayPasswordData['payPassword'] = password_hash($updatePayPasswordData['payPassword'], PASSWORD_DEFAULT);
- $result = $this->objMCustomer->updatePayPassword($updatePayPasswordData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 校验余额支付密码
- */
- public function checkPayPassword()
- {
- $params = $this->request->getRawJson();
- if (!$params) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $checkPayPasswordData = [
- 'enterpriseId' => $this->onlineEnterpriseId,
- 'id' => getArrayItem($params, 'id'),
- 'payPassword' => trim(getArrayItem($params, 'payPassword')),
- ];
- foreach ($checkPayPasswordData as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMCustomer->checkPayPassword($checkPayPasswordData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取所有的明细
- */
- public function getAllMemberBalanceDetail()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $params['userCenterId'] = $this->onlineUserId;
- $params['customerId'] = getArrayItem($params, 'customerId', '');
- $returnData = $this->objMMemberBalanceDetail->getAllMemberBalanceDetail($params);
- if ($returnData->isSuccess()) {
- $returnData = $returnData->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 申请提现
- */
- public function addReflectDetail()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $ReflectDetailDate = [
- 'customerId' => getArrayItem($params, 'customerId', ''),
- 'userCenterId' => $this->onlineUserId,
- 'reflectType' => getArrayItem($params, 'reflectType', ''),
- 'money' => getArrayItem($params, 'money', ''),
- 'reflectInfo' => getArrayItem($params, 'reflectInfo', []),
- 'reflectStatus' => getArrayItem($params, 'reflectStatus', 4),
- 'auditStatus' => getArrayItem($params, 'auditStatus', StatusCode::$auditStatus['auditing']),
- ];
- foreach ($ReflectDetailDate as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $ReflectDetailDate['reflectInfo'] = json_encode($ReflectDetailDate['reflectInfo']);
- $ReflectDetailDate['remark'] = getArrayItem($params, 'remark', '');
- $ReflectDetailDate['createTime'] = time();
- $result = $this->objMReflectDetail->addReflectDetail($ReflectDetailDate);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 所有提现记录
- */
- public function getAllReflectDetail()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $params['start'] = getArrayItem($params, 'start', "");
- $params['end'] = getArrayItem($params, 'end', "");
- $params['customerId'] = getArrayItem($params, 'customerId', '');
- $returnData = $this->objMReflectDetail->getAllReflectDetail($params);
- if ($returnData->isSuccess()) {
- $returnData = $returnData->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 积分流水
- */
- public function getAllCustomerIntegralDesc()
- {
- $params = $this->request->getRawJson();
- $page = isset($params['page']) ? $params['page'] : 1;
- $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
- $pageParams = pageToOffset($params['page'], $params['pageSize']);
- $data['limit'] = $pageParams['limit'];
- $data['offset'] = $pageParams['offset'];
- $data['customerId'] = $params['customerId'];
- if (empty($params['customerId'])) {
- parent::sendOutput('customerId参数为空', ErrorCode::$paramError);
- }
- if (isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])) {
- $data['createTime'] = [
- 'star' => $params['star'],
- 'end' => $params['end']
- ];
- }
- $modelResult = $this->objMCustomer->getAllCustomerIntegralDesc($data);
- if (!$modelResult->isSuccess()) {
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- $returnData = $modelResult->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * 小程序充值
- */
- public function rechargeMemberBalance()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- //记录流水
- $memberBalanceDetailData = [
- 'customerId' => $params['customerId'],
- 'type' => StatusCode::$standard,
- 'userCenterId' => $this->onlineUserId,
- 'money' => $params['money'],
- 'purpose' => '充值',
- 'orderIds' => '',
- 'remark' => '充值' . $params['money'],
- 'financeType' => '会员余额充值',
- ];
- foreach ($memberBalanceDetailData as $k => $v) {
- if (in_array($k, ['customerId', 'money', 'purpose']) && empty($v)) {
- $this->sendOutput('请输入' . $k, ErrorCode::$paramError);
- }
- }
- $result = $this->objMMemberBalanceDetail->addMemberBalanceDetail($memberBalanceDetailData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 小程序客户余额明细列表
- */
- public function getAllCustomerBalanceDetail()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
- ];
- foreach ($selectParams as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $selectParams['start'] = !empty($params['start']) ? $params['start'] : 0;
- $selectParams['end'] = !empty($params['end']) ? strtotime(date('Y-m-d', $params['end']) . '23:59:59') : time();
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $result = $this->objMCustomerBalanceDetail->getAllCustomerBalanceDetail($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- 'openingBalance' => $returnData['openingBalance'],
- 'endingBalance' => $returnData['endingBalance'],
- 'shouldReceiveTotal' => $returnData['shouldReceiveTotal'],
- 'actualReceiveTotal' => $returnData['actualReceiveTotal'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|