123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2018/11/22
- * Time: 下午4:51
- */
- namespace app\common\service;
- use app\admin\model\PalmpaySubAccount;
- use app\api\library\OrderDeduction;
- use app\common\constants\Order;
- use app\common\model\OrdersCollect;
- use app\main\service\AdminKlUpdateService;
- use app\main\service\KlService;
- use app\main\constants\PayConstants;
- use app\main\service\OfficialAccountsService;
- use think\db\Query;
- use think\Log;
- /**
- * 订单信息处理
- * Class OrderService
- * @package app\common\service
- */
- class OrderService extends BaseService
- {
- /**
- * @var OrderService
- */
- private static $self;
- /**
- * @return OrderService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * @return OrdersCollect
- */
- public function getOrderCollectModel()
- {
- return model('OrdersCollect');
- }
- public function getMonthReport($admin_id, $date_range, $offset, $limit,$business_line = PayConstants::BUSINESS_WECHAT)
- {
- $default = [
- 'code' => 1,
- 'data' => [
- 'total' => 0,
- 'rows' => [],
- ],
- ];
- try {
- $channel_ids = AdminService::instance()->getVipAdminBindModel()->getChannelIds($admin_id);
- if (!$channel_ids) {
- return $default;
- }
- $fields = [
- 'LEFT(createdate,6)' => 'create_month',
- 'IFNULL(SUM(o.recharge_money),0)' => 'recharge_money',
- 'IFNULL(SUM(o.normal_recharge_money),0)' => 'normal_recharge_money',
- 'IFNULL(SUM(o.vip_recharge_orders_count),0)' => 'vip_recharge_orders_count',
- 'IFNULL(SUM(o.normal_recharge_orders),0)' => 'normal_recharge_orders',
- 'IFNULL(SUM(o.vip_recharge_money),0)' => 'vip_recharge_money',
- 'IFNULL(SUM(o.vip_recharge_orders),0)' => 'vip_recharge_orders',
- 'IFNULL(SUM(o.recharge_money_benefit),0)' => 'recharge_money_benefit',
- 'o.type',
- 'o.flag',
- ];
- $total = $this->getRechargeOptions($date_range, $fields, false)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->group('o.type, o.flag, create_month')
- ->count();
- $all_list = $this->getRechargeOptions($date_range, $fields, false)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->field($fields)
- ->group('o.type, o.flag, create_month')
- ->limit($offset, $limit)
- ->select();
- $current_page_createdate = [];
- foreach ($all_list as $channel_order) {
- $current_page_createdate[] = $channel_order['create_month'];
- }
- $agent_list = $this->getRechargeOptions($date_range, $fields, false)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_BRANCH)
- ->where('o.business_line', $business_line)
- ->whereIn('LEFT(createdate,6)', $current_page_createdate)
- ->whereIn('o.admin_id', $channel_ids)
- ->order(['create_month' => 'asc'])
- ->field($fields)
- ->group('o.type, o.flag, create_month')
- ->select();
- $channel_list = $this->getRechargeOptions($date_range, $fields, false)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_SELF)
- ->where('o.business_line', $business_line)
- ->whereIn('LEFT(createdate,6)', $current_page_createdate)
- ->whereIn('o.admin_id', $channel_ids)
- ->order(['create_month' => 'asc'])
- ->field($fields)
- ->group('o.type, o.flag, create_month')
- ->select();
- $channel_data = $this->processChannelResult($all_list, $channel_list, $agent_list);
- return [
- 'code' => 0,
- 'data' => [
- 'total' => $total,
- 'rows' => $channel_data,
- ],
- ];
- } catch (\Exception $e) {
- Log::log($e->getMessage() . $e->getFile() . $e->getLine());
- return $default;
- }
- }
- public function getDayReport($admin_id, $date_range, $offset, $limit, $business_line = PayConstants::BUSINESS_WECHAT)
- {
- $default = [
- 'code' => 1,
- 'data' => [
- 'total' => 0,
- 'rows' => [],
- ],
- ];
- try {
- $channel_ids = AdminService::instance()->getVipAdminBindModel()->getChannelIds($admin_id);
- if (!$channel_ids) {
- return $default;
- }
- $fields = [
- 'createdate',
- 'IFNULL(SUM(o.recharge_money),0)' => 'recharge_money',
- 'IFNULL(SUM(o.normal_recharge_money),0)' => 'normal_recharge_money',
- 'IFNULL(SUM(o.vip_recharge_orders_count),0)' => 'vip_recharge_orders_count',
- 'IFNULL(SUM(o.normal_recharge_orders),0)' => 'normal_recharge_orders',
- 'IFNULL(SUM(o.vip_recharge_money),0)' => 'vip_recharge_money',
- 'IFNULL(SUM(o.vip_recharge_orders),0)' => 'vip_recharge_orders',
- 'IFNULL(SUM(o.recharge_money_benefit),0)' => 'recharge_money_benefit',
- 'o.type',
- 'o.flag',
- ];
- $total = $this->getRechargeOptions($date_range, $fields)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->group('o.type, o.flag, createdate')
- ->count();
- $all_list = $this->getRechargeOptions($date_range, $fields)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->field($fields)
- ->group('o.type, o.flag, createdate')
- ->limit($offset, $limit)
- ->select();
- $current_page_createdate = [];
- foreach ($all_list as $channel_order) {
- $current_page_createdate[] = $channel_order['createdate'];
- }
- $agent_list = $this->getRechargeOptions($date_range, $fields)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_BRANCH)
- ->where('o.business_line', $business_line)
- ->whereIn('o.createdate', $current_page_createdate)
- ->whereIn('o.admin_id', $channel_ids)
- ->order(['createdate' => 'asc'])
- ->field($fields)
- ->group('o.type, o.flag, createdate')
- ->select();
- $channel_list = $this->getRechargeOptions($date_range, $fields)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_SELF)
- ->where('o.business_line', $business_line)
- ->whereIn('o.createdate', $current_page_createdate)
- ->whereIn('o.admin_id', $channel_ids)
- ->order(['createdate' => 'asc'])
- ->field($fields)
- ->group('o.type, o.flag, createdate')
- ->select();
- $channel_data = $this->processChannelResult($all_list, $channel_list, $agent_list);
- return [
- 'code' => 0,
- 'data' => [
- 'total' => $total,
- 'rows' => $channel_data,
- ],
- ];
- } catch (\Exception $e) {
- Log::log($e->getMessage() . $e->getFile() . $e->getLine());
- return $default;
- }
- }
- /**
- * @param $admin_id
- * @param $date_range
- * @param $offset
- * @param $limit
- * @return array
- */
- public function getMonthServiceReport($admin_id, $date_range, $offset, $limit, $filter=[], $business_line = PayConstants::BUSINESS_WECHAT)
- {
- $default = [
- 'code' => 1,
- 'data' => [
- 'total' => 0,
- 'rows' => [],
- ],
- ];
- try {
- $channel_ids = AdminService::instance()->getVipAdminBindModel()->getChannelIds($admin_id);
- if (!$channel_ids) {
- return $default;
- }
- $fields = [
- 'admin.username',
- 'admin.id',
- 'LEFT(createdate,6)' => 'create_month',
- 'IFNULL(SUM(o.recharge_money),0)' => 'recharge_money',
- 'IFNULL(SUM(o.normal_recharge_money),0)' => 'normal_recharge_money',
- 'IFNULL(SUM(o.vip_recharge_orders_count),0)' => 'vip_recharge_orders_count',
- 'IFNULL(SUM(o.normal_recharge_orders),0)' => 'normal_recharge_orders',
- 'IFNULL(SUM(o.vip_recharge_money),0)' => 'vip_recharge_money',
- 'IFNULL(SUM(o.vip_recharge_orders),0)' => 'vip_recharge_orders',
- 'IFNULL(SUM(o.recharge_money_benefit),0)' => 'recharge_money_benefit',
- 'replace(JSON_EXTRACT(json,"$.authorizer_info.nick_name"),\'"\',\'\')' => 'wx_nickname',
- 'o.type',
- 'o.flag',
- ];
- $total = $this->getRechargeOptions($date_range, $fields, false, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->group('admin.id, o.type, o.flag, create_month, wx_nickname')
- ->count();
- $all_list = $this->getRechargeOptions($date_range, $fields, false, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->order(['LEFT(createdate,6)' => 'asc'])
- ->field($fields)
- ->group('admin.id, o.type, o.flag, create_month, wx_nickname')
- ->limit($offset, $limit)
- ->select();
- $current_page_channel_ids = $current_page_createdate = [];
- foreach ($all_list as $channel_order) {
- $current_page_channel_ids[] = $channel_order['id'];
- $current_page_createdate[] = $channel_order['create_month'];
- }
- $agent_list = $this->getRechargeOptions($date_range, $fields, false, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_BRANCH)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $current_page_channel_ids)
- ->whereIn('LEFT(createdate,6)', $current_page_createdate)
- ->order(['create_month' => 'asc'])
- ->field($fields)
- ->group('admin.id, o.type, create_month, wx_nickname')
- ->select();
- $channel_list = $this->getRechargeOptions($date_range, $fields, false, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_SELF)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $current_page_channel_ids)
- ->whereIn('LEFT(createdate,6)', $current_page_createdate)
- ->order(['create_month' => 'asc'])
- ->field($fields)
- ->group('admin.id, o.type, create_month, wx_nickname')
- ->select();
- $channel_data = $this->processChannelResult($all_list, $channel_list, $agent_list);
- return [
- 'code' => 0,
- 'data' => [
- 'total' => $total,
- 'rows' => $channel_data,
- ],
- ];
- } catch (\Exception $e) {
- Log::log($e->getMessage());
- return $default;
- }
- }
- /**
- * @param $admin_id
- * @param $date_range
- * @param $offset
- * @param $limit
- * @return array
- */
- public function getDayServiceReport($admin_id, $date_range, $offset, $limit, $filter=[], $business_line = PayConstants::BUSINESS_WECHAT)
- {
- $default = [
- 'code' => 1,
- 'data' => [
- 'total' => 0,
- 'rows' => [],
- ],
- ];
- try {
- $channel_ids = AdminService::instance()->getVipAdminBindModel()->getChannelIds($admin_id);
- if (!$channel_ids) {
- return $default;
- }
- $fields = [
- 'admin.username',
- 'admin.id',
- 'o.createdate',
- 'replace(JSON_EXTRACT(json,"$.authorizer_info.nick_name"),\'"\',\'\')' => 'wx_nickname',
- 'o.recharge_money',
- 'o.normal_recharge_orders',
- 'o.vip_recharge_orders',
- 'o.normal_recharge_money',
- 'o.vip_recharge_money',
- 'o.recharge_money',
- 'o.recharge_money_benefit',
- 'o.flag',
- 'o.type',
- 'o.createdate',
- ];
- $total = $this->getRechargeOptions($date_range, $fields, true, $filter )
- ->whereIn('o.admin_id', $channel_ids)
- ->where('o.business_line', $business_line)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)->count();
- $all_list = $this->getRechargeOptions($date_range, $fields, true, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_ALL)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $channel_ids)
- ->order(['o.createdate' => 'desc', 'recharge_money' => 'desc', 'o.admin_id' => 'asc'])
- ->limit($offset, $limit)
- ->select();
- $current_page_channel_ids = $current_page_createdate = [];
- foreach ($all_list as $channel_order) {
- $current_page_channel_ids[] = $channel_order['id'];
- $current_page_createdate[] = $channel_order['createdate'];
- }
- $agent_list = $this->getRechargeOptions($date_range, $fields, true, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_BRANCH)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $current_page_channel_ids)
- ->whereIn('o.createdate', $current_page_createdate)
- ->select();
- $channel_list = $this->getRechargeOptions($date_range, $fields,true, $filter)
- ->where('o.flag', Order::ORDER_COLLECT_FLAG_SELF)
- ->where('o.business_line', $business_line)
- ->whereIn('o.admin_id', $current_page_channel_ids)
- ->whereIn('o.createdate', $current_page_createdate)
- ->select();
- $channel_data = $this->processChannelResult($all_list, $channel_list, $agent_list);
- return [
- 'code' => 0,
- 'data' => [
- 'total' => $total,
- 'rows' => $channel_data,
- ],
- ];
- } catch (\Exception $e) {
- Log::alert($e->getMessage() . $e->getFile() . $e->getLine());
- return $default;
- }
- }
- /**
- * @param $item
- * @return string
- */
- public function processUniqueKey($item)
- {
- $item = $item->toArray();
- $return_keys = [];
- $keys = ['createdate', 'create_month', 'id'];
- foreach ($keys as $key) {
- if (array_key_exists($key, $item)) {
- $return_keys[] = $item[$key];
- }
- }
- return implode('-', $return_keys);
- }
- public function processChannelResult($all_list, $channel_list, $agent_list)
- {
- $result = [];
- if ($all_list) {
- $agent_data = [];
- //代理商
- foreach ($agent_list as $item) {
- $key = $this->processUniqueKey($item);
- $agent_data[$key] = [
- 'recharge_money' => $item['recharge_money'],
- 'recharge_money_benefit' => $item['recharge_money_benefit'],
- ];
- }
- $channel_data = [];
- //渠道商
- foreach ($channel_list as $item) {
- $key = $this->processUniqueKey($item);
- $channel_data[$key] = [
- 'recharge_money' => $item['recharge_money'],
- 'recharge_money_benefit' => $item['recharge_money_benefit'],
- ];
- }
- //统计结果
- foreach ($all_list as $item) {
- $key = $this->processUniqueKey($item);
- //self_recharge->渠道商本身的充值金额
- //self_recharge_benefit->渠道商的分成收益:渠道商本身的充值 * 渠道商分成比例1
- if(array_key_exists($key, $channel_data)){
- $item['self_recharge'] = $channel_data[$key]['recharge_money'];
- $item['self_recharge_benefit'] = $channel_data[$key]['recharge_money_benefit'];
- }else{
- $item['self_recharge'] = 0;
- $item['self_recharge_benefit'] = 0;
- }
- $item['total_benefit'] = $item['recharge_money_benefit'];
- if (array_key_exists($key, $agent_data)) {
- $item['total_benefit'] = $item['recharge_money_benefit'] - $agent_data[$key]['recharge_money_benefit'];
- $item['agent_benefit'] = $agent_data[$key]['recharge_money_benefit'];
- $item['agent_recharge'] = $agent_data[$key]['recharge_money'];
- } else {
- $item['agent_benefit'] = 0;
- $item['agent_recharge'] = 0;
- }
- $result[] = $item;
- }
- }
- return $result;
- }
- /**
- * @param $date_range
- * @param $fields
- * @param $day
- * @return Query
- */
- public function getRechargeOptions($date_range, $fields, $day = true, $filter=[], $business_line = PayConstants::BUSINESS_WECHAT)
- {
- $time = explode(',', $date_range);
- $where = [];
- if ( isset($filter['username']) && !empty($filter['username'])){
- $where['admin.username'] = $filter['username'];
- }
- if (!$day) {
- $time[0] .= '00';
- //获取前一天的日期格式
- if ($time[1] == date('Ym')) {
- $time[1] = $time[1] . str_pad(date('d') - 1, 2, '0', STR_PAD_LEFT);
- }else{
- $time[1] .= '31';
- }
- }
- $query = $this->getOrderCollectModel()
- ->alias('o')
- ->where('o.business_line', $business_line)
- ->join('admin', "o.admin_id=admin.id", "LEFT")
- ->join('admin_config', "admin.id=admin_config.admin_id", "LEFT")
- ->where("type", '=', Order::ORDER_COLLECT_TYPE_DAY)
- ->where($where)
- ->where("createdate>=$time[0]")
- ->where("createdate<=$time[1]")
- ->field($fields);
- return $query;
- }
- /**
- * @param $channelIds
- * @param $date
- * @return int|mixed
- */
- public function getVipDataRangeTime($channelIds, $date, $business_line = PayConstants::BUSINESS_WECHAT)
- {
- try{
- $result = $this->getOrderCollectModel()
- ->where('business_line', $business_line)
- ->field(['sum(recharge_money)' => 'recharge_money'])
- ->where(['type' => 1, 'flag' => 3, 'admin_id' => ['in', $channelIds], 'createdate' => $date])
- ->find();
- if($result){
- return $result['recharge_money'];
- }
- return 0;
- }catch (\Exception $e){
- Log::alert($e->getMessage() . $e->getFile() . $e->getLine());
- return 0;
- }
- }
- /**
- * 分账参数
- * @param $money
- * @param $channelId
- * @return \app\common\model\object\ReturnObject
- */
- public function getPalmPayCmd($money, $channelId)
- {
- if($money==0) return false;
- $dzAccount = $this->getDzAccount(get_host_no_port())->data;
- $default = ['dz_palmpay_sub_account_id'=>'','dz_amount'=>0,'channel_palmpay_sub_account_id'=>'','channel_amount'=>0];
- if ($dzAccount) {
- $cmd = [
- 'SFJOrdertype' => '1',
- 'remarktype' => 'JHS0100000',
- 'plantCode' => '4032',
- ];
- $channelAccount = $this->getChannelAccount($dzAccount['palmpay_company_id'], $channelId)->data;
- if ($channelAccount && $dzAccount['palmpay_company_id'] == $channelAccount['palmpay_company_id']) { //分账主体一致才分账
- $adminExtend = \app\main\service\AdminService::instance()->getAdminExtendModel()->getInfo($channelId);
- $rate = $adminExtend['benefit'];
- $channelMoney = number_format(floatval($rate) * floatval($money),2,'.','');
- $dzMoney = number_format(floatval($money) - $channelMoney,2,'.','');
- if($channelMoney > 0) {
- $default['channel_palmpay_sub_account_id'] = $channelAccount['sub_account_code'];
- $default['channel_amount'] = $channelMoney;
- $cmd['oderlist'][] = $this->getOrderItem($channelMoney, $channelAccount['sub_account_code'])->data;
- }
- if($dzMoney > 0) {
- $default['dz_palmpay_sub_account_id'] = $dzAccount['sub_account_code'];
- $default['dz_amount'] = $dzMoney;
- $cmd['oderlist'][] = $this->getOrderItem($dzMoney, $dzAccount['sub_account_code'])->data;
- }
- } else { //主体不一致,钱款打点众子账户
- $cmd['oderlist'][] = $this->getOrderItem($money, $dzAccount['sub_account_code'])->data;
- $default['dz_palmpay_sub_account_id'] = $dzAccount['sub_account_code'];
- $default['dz_amount'] = $money;
- }
- $json = json_encode([$cmd]);
- $return = urlencode($json);
- } else {
- $return = false;
- }
- return $this->setData(['cmd'=>$return,'default'=>$default])->getReturn();
- }
- /**
- * 获取分账单
- * @param $dzMoney
- * @param $SubAccNo
- * @return \app\common\model\object\ReturnObject
- */
- public function getOrderItem($dzMoney, $SubAccNo)
- {
- $tmp = [
- 'SubAccNo' => $SubAccNo,
- 'PayModel' => '1',
- 'TranFee' => '0.00',
- 'subamount' => (string)$dzMoney,
- 'suborderId' => $this->getUniqueOrder()->data,
- 'object' => '支付-' . $SubAccNo,
- ];
- return $this->setData($tmp)->getReturn();
- }
- /**
- * 获取分账订单唯一值
- * @return \app\common\model\object\ReturnObject
- */
- public function getUniqueOrder()
- {
- $data = substr(md5(substr_replace(uniqid() ,getmypid(),0,strlen(getmypid())). substr(microtime(),2,6) . uniqid()), 0, 22);
- return $this->setData($data)->getReturn();
- }
- /**
- * 获取点众账号子商户
- * @param $host
- * @return \app\common\model\object\ReturnObject
- */
- public function getDzAccount($host)
- {
- $dzAccount = OfficialAccountsService::instance()->getWxpayModel()
- ->alias('wx')
- ->join('palmpay_sub_account', 'palmpay_sub_account.id=wx.palmpay_sub_account_ids', 'LEFT')
- ->where('wx.pay_host', $host)
- ->whereNotNull('palmpay_sub_account.id')
- ->find();
- return $this->setData($dzAccount)->getReturn();
- }
- /**
- * 获取渠道账号子商户
- * @param $palmpay_company_id
- * @return \app\common\model\object\ReturnObject
- */
- public function getChannelAccount($palmpay_company_id, $channelId)
- {
- $adminConfig = \app\main\service\AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channelId);
- $channelAccount = false;
- if ($adminConfig && $adminConfig['palmpay_sub_account_ids']) {
- $subAccountMap = json_decode($adminConfig['palmpay_sub_account_ids'], true);
- $subAccountArr=array_column($subAccountMap,'palmpay_sub_account_id','company_id');
- if(array_key_exists($palmpay_company_id,$subAccountArr)){
- $subAccountId = $subAccountArr[$palmpay_company_id];
- $palmpaySubAccount = new PalmpaySubAccount();
- $channelAccount = $palmpaySubAccount->where('id', $subAccountId)->find();
- }
- }
- return $this->setData($channelAccount)->getReturn();
- }
- /**
- * 获取订单扣量账号
- * @param $groupId
- * @param $adminId
- * @param $channelId
- * @param $insertData
- * @param $isActivity
- * @return \app\common\model\object\ReturnObject
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getKlAdminInfo($groupId, $adminId, $channelId, $insertData, $isActivity = false)
- {
- $orderDeduction = new OrderDeduction();
- $adminInfo = false;
- if ($channelId) {
- if ($rule_config = KlService::instance()->getKlRule($channelId)) {
- $adminInfo = AdminKlUpdateService::instance()->getKlAdmin($channelId, $insertData, $rule_config)->data;
- }else{
- $adminInfo = $orderDeduction->orderKL($adminId, $channelId, $insertData, $isActivity);
- }
- }
- //订单转移
- if ($groupId == 4 && !$adminInfo) {
- $adminInfo = $orderDeduction->orderTransfer($adminId, $channelId, $insertData, $isActivity);
- }
- if($adminInfo){
- $this->setData($adminInfo);
- }
- return $this->getReturn();
- }
- }
|