| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <?php
- namespace addons\AvoidTax\common\service;
- use addons\AvoidTax\common\jdk\luyong\BaseApi;
- use addons\AvoidTax\common\models\LyImportSignUser;
- use addons\AvoidTax\common\models\LySilentSign;
- use addons\AvoidTax\common\models\TaxOrder;
- use Exception;
- use yii\helpers\Json;
- /**
- * LuYongService class
- * @package addons\AvoidTax\common\service
- */
- class LuYongService extends BaseService
- {
- /**
- * @var BaseApi
- */
- private $api;
- /**
- * @var array
- */
- protected $response;
- /**
- * @return array
- */
- public function getResponse()
- {
- return $this->response;
- }
- public function init()
- {
- parent::init();
- $service = new TaxConfigService(['mall_id' => $this->mall_id]);
- $config = $service->getLYConfig();
- // 去除空格
- $config = array_map(function($item) {
- return trim($item);
- }, $config);
- $this->api = new BaseApi([
- 'email' => $config['email'],
- 'pwd' => $config['pwd'],
- 'accountId' => $config['accountId'],
- 'publicKey' => $config['publicKey'],
- 'privateKey' => $config['privateKey'],
- ]);
- // $this->api->setTest();
- }
- /**
- * 无感电签
- *
- * @param integer $uid
- * @param string $name
- * @param string $phone
- * @param string $id_card
- * @return boolean
- */
- public function silentSign(int $uid, string $name, string $phone, string $id_card)
- {
- try {
- $this->response = $this->api->silentSign($name, $phone, $id_card);
- LySilentSign::addSilentSign(
- $this->mall_id,
- $uid,
- $name,
- $phone,
- $id_card,
- $this->api->accountId,
- $this->response
- );
- if ($this->response['code'] == '0000') {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- return true;
- }
- /**
- * 查询身份证是否签约
- *
- * @param string $idCard
- * @return boolean
- */
- public function querySignUserByIdCard(string $idCard)
- {
- try {
- $this->response = $this->api->querySignUserByIdCard($idCard);
- if ($this->response['code'] == 200 && $this->response['data']['status'] == 1) {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 查询用户是否注册
- *
- * @param string $idCard
- * @return boolean
- */
- public function queryRegisterUser(string $idCard)
- {
- try {
- $this->response = $this->api->queryRegisterUser($idCard);
- if ($this->response['code'] == 200 && $this->response['data']['result'] == true) {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 批量导入签约用户接口
- *
- * @param integer $uid
- * @param string $name
- * @param string $phone
- * @param string $idCard
- * @return boolean
- */
- public function importSignUser(int $uid, string $name, string $phone, string $idCard)
- {
- $batchNum = date('YmdHis') . mt_rand(100, 999);
- $signUsers = [compact('name', 'phone', 'idCard')];
- try {
- $this->response = $this->api->importSignUser($batchNum, $signUsers);
- LyImportSignUser::addImportSignUser(
- $uid, $this->mall_id, $batchNum, $signUsers, $this->response
- );
- if ($this->response['code'] == 200 && $this->response['msg'] == '处理成功') {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 支付时异步请求接口
- *
- * @param TaxOrder $order 用户提现的订单
- * @param TaxOrder $tax_order 手续费的订单
- * @param LySilentSign $sign 用户签约信息
- * @return boolean
- */
- public function asyncTransferNotify(TaxOrder $order, TaxOrder $tax_order, LySilentSign $sign)
- {
- $batchNo = $order->batch_num;
- try {
- $this->response = $this->api->asyncTransferNotify($batchNo);
- if ($this->response['code'] == 200) {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 订单失败通知
- *
- * @param TaxOrder $user_order
- * @return boolean
- */
- public function asyncTransferResultNotifyNo(TaxOrder $user_order)
- {
- try {
- $this->response = $this->api->asyncTransferResultNotifyNo(
- $user_order->order_sn
- );
- if ($this->response['code'] == 200) {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 订单完成通知
- *
- * @param TaxOrder $order
- * @return boolean
- */
- public function asyncTransferResultNotifyOk(TaxOrder $user_order)
- {
- try {
- $alipay = Json::decode($user_order->alipay_response);
- $this->response = $this->api->asyncTransferResultNotifyOk(
- $user_order->order_sn,
- $alipay['pay_fund_order_id'] // 支付宝成功订单号
- );
- if ($this->response['code'] == 200) {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 打款批次风控接口
- *
- * @return boolean
- */
- public function riskCheck(TaxOrder $order, LySilentSign $sign)
- {
- try {
- $this->response = $this->api->riskCheck($order->batch_num, [
- [
- 'name' => $sign->name,
- 'idCard' => $sign->id_card,
- 'afterTaxMoney' => $order->amount,
- 'remark' => '',
- 'account' => $order->mobile,
- 'bizOutNo' => $order->order_sn,
- ]
- ]);
- if ($this->response['code'] == 200) {
- return true;
- }
- return $this->error($this->response['msg']);
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
|