| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139 |
- <?php
- namespace api\modules\v1\controllers\userwages;
- use addons\AvoidTax\common\models\TaxUserAuth;
- use addons\AvoidTax\common\service\AuthService;
- use addons\AvoidTax\common\service\UserService;
- use addons\AvoidTax\common\service\XinlongService;
- use addons\MerchantAuth\common\models\MerchantAuthLog;
- use addons\Salary\common\logic\PushLogic;
- use addons\Salary\common\logic\UserLogic;
- use addons\Salary\common\models\SalaryMerchant;
- use addons\Salary\common\models\SalaryUserLog;
- use addons\Salary\common\services\WyaServices;
- use common\enums\ApiStatusEnum;
- use common\enums\StatusEnum;
- use common\enums\WithdrawWayEnum;
- use common\globals\GlobalInvoke;
- use common\helpers\ArrayHelper;
- use common\helpers\DateHelper;
- use common\helpers\sms\Sms;
- use common\models\common\CapitalLog;
- use common\models\common\CapitalLogRelation;
- use common\models\common\CommissionLog;
- use common\models\common\CommissionMonthBilling;
- use common\models\common\CommissionYearsBilling;
- use common\models\common\PlatformSetting;
- use common\models\common\UserBankCard;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- use common\models\user\UserInfo;
- use common\models\user\UserWallet;
- use common\models\user\UserWithdrawLog;
- use yii\helpers\Json;
- use Yii;
- class UserController extends BaseController
- {
- /**
- * @var string
- */
- public $modelClass = '';
- //首页
- public function actionIndex()
- {
- $user_wallet = UserWallet::getOne([['user_id' => $this->userwages['id']], ['status' => StatusEnum::ENABLED]], true);
- $data = [
- 'commission_withdrawal' => 0,
- 'commission' => 0,
- 'frozen_commission' => 0,
- 'total_commission' => 0,
- 'commission_list' => [],
- ];
- if (!empty($user_wallet)) {
- $data['commission'] = $user_wallet['commission'];
- $data['commission_withdrawal'] = $user_wallet['commission_withdrawal'];
- $data['frozen_commission'] = $user_wallet['frozen_commission'];
- $data['total_commission'] = $user_wallet['total_commission'];
- }
- $commission_list = CommissionLog::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->userwages['id']]
- ],
- 'limit' => '3',
- 'order' => 'id desc',
- 'select' => 'id,change_num,desc,change_type,created_at'
- ]);
- if (!empty($commission_list)) {
- foreach ($commission_list as &$val) {
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- if ($val['change_type'] == 'add') {
- $val['change_type_text'] = '销售收入';
- } else {
- $val['change_type_text'] = '收入提现';
- }
- }
- $data['commission_list'] = $commission_list;
- }
- $data['id'] = $this->userwages['id'];
- $data['nickname'] = $this->userwages['nickname'];
- $data['mobile'] = $this->userwages['mobile'];
- $data['avatar_url'] = $this->userwages['avatar_url'];
- $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic');
- $data['is_eject'] = 0;// 是否已签约,0=否,1=是
- $data['is_popup'] = $config['is_sign'] ?? 0;// 是否强制弹窗,0=否,1=是
- $data['url'] = '';
- $data['accountId'] = '';
- $data['flowId'] = '';
- $data['pic_url'] = $config['pic_url'] ?? '';
- $data['link_text'] = $config['link_text'] ?? '-- 七件事集团技术支持 --';
- if(MallAddons::isInstall($this->mall_id, 'AvoidTax')){
- try {
- $service = new UserService(['mall_id' => $this->mall_id]);
- if ($service->checkSign($this->userwages['id'])) {
- $data['is_eject'] = 1;
- } else {
- $data['is_eject'] = 0;
- }
- } catch (\Exception $e) {
- return $this->error('支付宝合规:' . $e->getMessage());
- }
- }
- $data['merchant_status'] = -2;
- if (MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
- $model = MerchantAuthLog::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id'], 'status' => StatusEnum::ENABLED, 'is_poss' => [0, 1]]);
- $data['merchant_status'] = -1;
- if (!empty($model)) {
- if ($model['is_poss'] == 1) {
- $data['merchant_status'] = 1;
- }
- if ($model['is_poss'] == 0) {
- $data['merchant_status'] = 0;
- }
- }
- }
- $capital = ['balance' => 'balance', 'score' => 'score', 'redpack' => 'redpack'];
- if (!empty($config['is_hide_asset']) && !empty($config['hide_assets'])) {
- $hideAssets = json_decode($config['hide_assets'], true) ?: [];
- if (in_array('balance', $hideAssets)) {
- unset($capital['balance']);
- }
- if (in_array('score', $hideAssets)) {
- unset($capital['score']);
- }
- if (in_array('redpack', $hideAssets)) {
- unset($capital['redpack']);
- }
- }
- $data['capital_list'] = $capital ? UserInfo::getCapital($this->mall_id, $this->user_id, json_encode(array_values($capital))) : [];
- return $this->success('成功', $data);
- }
- /**
- * 创建签约
- *
- * @return void
- */
- public function actionCreateAccount()
- {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['mobile'], 'required', 'message' => '请填写手机号码'],
- [['id_card'], 'required', 'message' => '请填写身份证号码'],
- [['name'], 'required', 'message' => '请填写姓名'],
- ['mobile', 'match', 'pattern' => '/^1\d{10}/', 'message' => '请输入正确的手机号码'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- try {
- $service = new UserService(['mall_id' => $this->mall_id]);
- // 新龙
- if ($service->getConfigService()->isXLApiType()) {
- $system = Yii::$app->services->setting->platform->get('system');
- $redirect_url = ($system['cat_h5_url'] ?? '') . '/#/pages/userWages/index?sign=' . $this->mall_id;
- $res = $service->xlSign(
- $this->userwages['id'], $params['name'], $params['mobile'], $params['id_card'], $redirect_url
- );
- if ($res === true) {
- return $this->success('签约成功');
- }
- if ($res === false) {
- return $this->success($service->getError());
- }
- return $this->success('ok', $res);
- }
- // 鹿用
- if ($service->getConfigService()->isLYApiType()) {
- $res = $service->silentSign($this->userwages['id'], $params['name'], $params['mobile'], $params['id_card']);
- if ($res === false) {
- return $this->error($service->getError());
- }
- return $this->success('签约成功');
- }
- } catch (\Exception $e) {
- $this->error('申请失败:' . $e->getMessage());
- }
- }
- public function actionRegisterSmsCode()
- {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['mobile'], 'required', 'message' => '请输入手机号码'],
- [['mobile','area_code'], 'integer'],
- [['sms_type'], 'string'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $area_code = '';// 初始化区号
- $gateways = 'domestic';// 默认国内短信
- // 检测是登录并且区号不为空则使用国际短信
- if (!empty($this->userwages) && !empty($this->userwages->area_code)) {
- $gateways = 'international';
- $area_code = $this->userwages->area_code;
- }
- // 判断是否有区号
- if (!empty($params['area_code']) && $params['area_code'] != 86) {
- $gateways = 'international';
- $area_code = $params['area_code'];
- }
- $params['sms_type'] = $params['sms_type'] ?: '';
- $sms = new Sms($this->mall_id, $gateways);
- try {
- if ($sms->sendCaptcha($params['mobile'], $area_code,$params['sms_type']) === false) return $this->error('发送失败');
- }catch (\Exception $e){
- return $this->error($e->getMessage());
- }
- return $this->success('发送成功');
- }
- public function actionSetLoginPassword()
- {
- try {
- if (\Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['mobile', 'captcha', 'password', 'confirm_password'], 'required'],
- ['mobile', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'],
- [['mobile'], 'integer'],
- ['password', 'string', 'length' => [6, 11]],
- ['confirm_password', 'compare', 'compareAttribute' => 'password', 'message' => '两次密码不一致'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $user = $this->userwages;
- if($user['mobile']!=$params['mobile']) return $this->error('请输入绑定的手机号码');
- //短信验证码
- if (YII_ENV == 'prod') {
- if (!Sms::checkValidateCode($params['mobile'], $params['captcha'],Sms::SMS_TYPE_UPDATE_PASS)) return $this->error('验证码不正确');
- }
- $user = User::findOne(['id'=>$user['id']]);
- $user->password = Yii::$app->getSecurity()->generatePasswordHash(trim($params['password']));
- if ($user->save() === false) return $this->error(User::getStaticError());
- return $this->success('设置成功');
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- //待结算明细与收益明细
- public function actionCommissionList()
- {
- $params = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['user_id' => $this->userwages['id']];
- if (!empty($params['type']) && $params['type'] == 'frozen') {
- CapitalLog::$capitalType = "commission_frozen";
- $where[] = ['status' => StatusEnum::DISABLED];
- } else {
- CapitalLog::$capitalType = "commission";
- }
- if (!empty($params['date'])) {
- $start_time = strtotime($params['date'] . ' 00:00:00');
- $end_time = strtotime(date('Ymd', strtotime($params['date'] . '+1 month -1 day')) . ' 23:59:59');
- $where[] = ['>=', 'created_at', $start_time];
- $where[] = ['<=', 'created_at', $end_time];
- }
- $params['where'] = $where;
- $params['select'] = 'id,change_num,desc,change_type,created_at';
- $list = CapitalLog::listPage(array_merge($params, ['order' => 'id desc']));
- if (!empty($list['list'])) {
- $ids = array_column($list['list'], 'id');
- CapitalLogRelation::$capitalType = "commission";
- $capitalLog_relation_list = CapitalLogRelation::lists([
- 'where' => [
- ['log_id' => $ids],
- ['source_type' => CapitalLog::$capitalType]
- ],
- 'index' => 'log_id'
- ]);
- foreach ($list['list'] as &$val) {
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- if ($val['change_type'] == 'add') {
- $val['change_type_text'] = '销售收入';
- } else {
- $val['change_type_text'] = '收入提现';
- }
- if(isset($capitalLog_relation_list[$val['id']])){
- $val['desc'] = $capitalLog_relation_list[$val['id']]['describe'];
- }
- }
- }
- return $this->success('操作成功', $list);
- }
- //待结算明细统计
- public function actionCommissionTotal()
- {
- $params = \Yii::$app->request->post();
- CapitalLog::$capitalType = "commission_frozen";
- if (!empty($params['type']) && $params['type'] == 'frozen') {
- CapitalLog::$capitalType = "commission_frozen";
- } else {
- CapitalLog::$capitalType = "commission";
- }
- $query = CapitalLog::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id']]);
- if (!empty($params['date'])) {
- $start_time = strtotime($params['date'] . ' 00:00:00');
- $end_time = strtotime(date('Ymd', strtotime($params['date'] . '+1 month -1 day')) . ' 23:59:59');
- $query->andWhere(['>=', 'created_at', $start_time]);
- $query->andWhere(['<=', 'created_at', $end_time]);
- }
- if (!empty($params['type']) && $params['type'] == 'frozen') {
- CapitalLog::$capitalType = "commission_frozen";
- $query->andWhere(['status' => StatusEnum::DISABLED]);
- $add_total = $query->sum('change_num');
- return $this->success('操作成功', ['add_total' => $add_total, 'sub_total' => 0]);
- } else {
- $query_copy = clone $query;
- $add_total = $query->andWhere(['change_type' => 'add'])->sum('change_num');
- $sub_total = $query_copy->andWhere(['change_type' => 'sub'])->sum('change_num');
- return $this->success('操作成功', ['add_total' => $add_total ?? 0, 'sub_total' => $sub_total ?? 0]);
- }
- }
- public function actionCashDetail()
- {
- $user_wallet = UserWallet::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id']]);
- $data['commission'] = $user_wallet['commission'] ?? 0;//可用佣金
- $start_time = strtotime(date('Y-m-1', time()) . ' 00:00:00');
- $end_time = strtotime(date('Y-m-t', time()) . ' 23:59:59');
- $where = ['user_id' => $this->userwages['id'], 'mall_id' => $this->mall_id, 'from' => 1, 'status' => [UserWithdrawLog::STATUS_ALREADY_TRANS]];
- $commission_withdrawal = UserWithdrawLog::find()->where($where)
- ->sum('num');
- $data['commission_withdrawal'] = $commission_withdrawal ?? 0;//已提现得总佣金
- $month_num = UserWithdrawLog::find()->where($where)
- ->andWhere(['>=', 'created_at', $start_time])->andWhere(['<=', 'created_at', $end_time])
- ->sum('num');
- $monday_time = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)) . ' 00:00:00');
- $sunday_time = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) . ' 23:59:59');
- $week_num = UserWithdrawLog::find()->where($where)
- ->andWhere(['>=', 'created_at', $monday_time])->andWhere(['<=', 'created_at', $sunday_time])
- ->sum('num');
- $data['month_num'] = $month_num ?? 0;
- $data['week_num'] = $week_num ?? 0;
- return $this->success('操作成功', $data);
- }
- //提现明细
- public function actionCashList()
- {
- $params = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['user_id' => $this->userwages['id']];
- $where[] = ['from' => 1];
- if (isset($params['status']) && $params['status'] !== '') $where[] = ['status' => $params['status']];
- $params['where'] = $where;
- $params['select'] = 'id,mall_id,user_id,order_no,num,actual_num,poundage_num,poundage_ratio,content,status,type';
- $params['order'] = 'id desc';
- $list = UserWithdrawLog::listPage($params);
- $list['status_map'] = UserWithdrawLog::$status_msg;
- $list['type_map'] = UserWithdrawLog::$type_msg;
- return $this->success('操作成功', $list);
- }
- public function actionWithdrawLogList()
- {
- $params = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['user_id' => $this->userwages['id']];
- if (isset($params['status'])) {
- $where[] = ['=', 'status', $params['status']];
- }
- $params['where'] = $where;
- // $params['select'] = 'id,change_num,desc,change_type,created_at';
- $list = UserWithdrawLog::listPage(array_merge($params, ['order' => 'id desc']));
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$val) {
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- }
- }
- return $this->success('操作成功', $list);
- }
- //账单统计
- public function actionBillingStatistics()
- {
- $params = \Yii::$app->request->post();
- $type = $params['type'] ?? 'month';
- switch ($type) {
- case 'month':
- $result = $this->monthBilling($params);
- return $this->success('操作成功', $result);
- case 'year':
- $result = $this->yearBilling($params);
- return $this->success('操作成功', $result);
- }
- }
- protected function monthBilling($params)
- {
- $current_month = date('Y-m', time());
- if (!empty($params['month'])) {
- $month = $params['month'];
- } else {
- $month = $current_month;
- }
- $data = [
- 'income_nums' => 0,
- 'expenditure_nums' => 0,
- 'expenditure_money' => 0,
- 'income_money' => 0,
- ];
- if ($month == $current_month) {
- //当前月
- $user_id = $this->userwages['id'];
- $start_time = strtotime($current_month . '-01 00:00:00');
- $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
- FROM qimall_commission_log where created_at>={$start_time} and user_id ={$user_id} GROUP BY mall_id,user_id,change_type";
- $list = \Yii::$app->db->createCommand($sql)->queryAll();
- foreach ($list as $item) {
- switch ($item['change_type']) {
- case 'add':
- $data['income_money'] = $item['SUM3'];
- $data['income_nums'] = $item['COUNT4'];
- break;
- case 'sub':
- $data['expenditure_money'] = $item['SUM3'];
- $data['expenditure_nums'] = $item['COUNT4'];
- break;
- }
- }
- } else {
- $where = [
- ['mall_id' => $this->mall_id], ['user_id' => $this->userwages['id']], ['month' => $month], ['status' => StatusEnum::ENABLED]];
- $res = CommissionMonthBilling::getOne($where, true, [], false, 'income_nums,expenditure_nums,expenditure_money,income_money');
- if (!empty($res)) $data = $res;
- }
- return $data;
- }
- protected function yearBilling($params)
- {
- $current_year = date('Y', time());
- if (!empty($params['year'])) {
- $year = $params['year'];
- } else {
- $year = $current_year;
- }
- $data = [
- 'income_nums' => 0,
- 'expenditure_nums' => 0,
- 'expenditure_money' => 0,
- 'income_money' => 0,
- ];
- if ($current_year == $year) {
- //当前年
- $user_id = $this->userwages['id'];
- $month = date('m', time());
- $start_time = strtotime($year . '-' . $month . '-01 00:00:00');
- $month_arr = [];
- $month = intval($month);
- for ($i = 1; $i < $month; $i++) {
- $tag = '-';
- if ($i < 10) {
- $tag = $tag . '0';
- }
- $month_arr[] = $year . $tag . $i;
- }
- //非当月,除历史统计数据查询
- $list = CommissionMonthBilling::lists([
- 'where' => [
- ['user_id' => $user_id],
- ['month' => $month_arr]
- ],
- 'select' => 'sum(income_money) as income_money,
- sum(income_nums) as income_nums,
- sum(expenditure_money) as expenditure_money,
- sum(expenditure_nums) as expenditure_nums'
- ]);
- foreach ($list as $val) {
- $data['income_money'] += $val['income_money'];
- $data['income_nums'] += $val['income_nums'];
- $data['expenditure_money'] += $val['expenditure_money'];
- $data['expenditure_nums'] += $val['expenditure_nums'];
- }
- //当月从佣金记录表查询
- $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
- FROM qimall_commission_log where created_at>={$start_time} and user_id ={$user_id} GROUP BY mall_id,user_id,change_type";
- $list = \Yii::$app->db->createCommand($sql)->queryAll();
- foreach ($list as $item) {
- switch ($item['change_type']) {
- case 'add':
- $data['income_money'] = bcadd($data['income_money'], $item['SUM3'], 2);
- $data['income_nums'] = bcadd($data['income_nums'], $item['COUNT4'], 2);
- break;
- case 'sub':
- $data['expenditure_money'] = bcadd($data['expenditure_money'], $item['SUM3'], 2);
- $data['expenditure_nums'] = bcadd($data['expenditure_nums'], $item['COUNT4'], 2);
- break;
- }
- }
- } else {
- $where = [
- ['mall_id' => $this->mall_id], ['user_id' => $this->userwages['id']], ['years' => $year], ['status' => StatusEnum::ENABLED]];
- $res = CommissionYearsBilling::getOne($where, true, [], false, 'income_nums,expenditure_nums,expenditure_money,income_money');
- if (!empty($res)) $data = $res;
- }
- return $data;
- }
- //月账单对比
- public function actionBillingContrast()
- {
- $params = \Yii::$app->request->post();
- $current_month = date('Y-m', time());
- $month = !empty($params['month']) ? $params['month'] : $current_month;
- $tags = '-';
- $date1 = explode($tags, $current_month . '-01');
- $date2 = explode($tags, $month . '-01');
- $cha = abs($date1[0] - $date2[0]) * 12 + ($date1[1] - $date2[1]);
- $month_arr = [];
- if ($cha <= 3) {
- for ($i = 5; $i >= 0; $i--) {
- $temp = "-{$i} Months";
- $month_arr[] = date("Y-m", strtotime($temp));
- }
- } else {
- $start_i = $cha + 2;
- $end_i = $cha - 3;
- for ($i = $start_i; $i >= $end_i; $i--) {
- $temp = "-{$i} Months";
- $month_arr[] = date("Y-m", strtotime($temp));
- }
- }
- //有当月
- $user_id = $this->userwages['id'];
- $where = [
- ['mall_id' => $this->mall_id],
- ['user_id' => $user_id],
- ['month' => $month_arr]
- ];
- $select = 'expenditure_money,income_money,month';
- $list = CommissionMonthBilling::lists(['where' => $where, 'select' => $select, 'index' => 'month']);
- if (in_array($current_month, $month_arr)) {
- $this_month = DateHelper::thisMonth();
- $start_time = $this_month['start'];
- $end_time = $this_month['end'];
- $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
- FROM qimall_commission_log where created_at <={$end_time} and created_at>={$start_time} and user_id ={$user_id} GROUP BY mall_id,user_id,change_type";
- $log_list = \Yii::$app->db->createCommand($sql)->queryAll();
- $current_month_income_money = 0;
- $current_month_income_nums = 0;
- $current_month_expenditure_money = 0;
- $current_month_expenditure_nums = 0;
- foreach ($log_list as $val) {
- if ($val['change_type'] == 'add') {
- $current_month_income_money = $val['SUM3'];
- // $current_month_income_nums = $val['COUNT4'];
- }
- if ($val['change_type'] == 'sub') {
- $current_month_expenditure_money = $val['SUM3'];
- // $current_month_expenditure_nums = $val['COUNT4'];
- }
- }
- $list[$current_month] = [
- 'expenditure_money' => $current_month_expenditure_money,
- // 'expenditure_nums' => $current_month_expenditure_nums,
- 'income_money' => $current_month_income_money,
- // 'income_nums' => $current_month_income_nums,
- 'month' => $current_month,
- ];
- }
- $data = [];
- foreach ($month_arr as $val) {
- $is_default = 0;
- if ($val == $month) $is_default = 1;
- $temp_arr = explode('-',$val);
- $temp_data = [
- 'expenditure_money' => 0,
- 'income_money' => 0,
- // 'expenditure_nums' => 0,
- // 'income_nums' => 0,
- 'month' =>$val,
- 'is_default' => $is_default];
- if($temp_arr[1]==1||$temp_arr[1]==12){
- $temp_data['month_str'] = $val;
- }else{
- $temp_data['month_str'] = $temp_arr[1];
- }
- if (isset($list[$val])) {
- $temp_arr = explode('-',$list[$val]['month']);
- if($temp_arr[1]==1||$temp_arr[1]==12){
- $list[$val]['month_str'] = $list[$val]['month'];
- }else{
- $list[$val]['month_str'] = $temp_arr[1];
- }
- $list[$val]['is_default'] = $is_default;
- $temp_data = $list[$val];
- }
- $data[] = $temp_data;
- }
- return $this->success('', $data);
- }
- /**
- * 新月度账单接口
- * @Author: lun
- * @DateTime: 2023/3/22 0022 10:14
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- * @throws \yii\db\Exception
- */
- public function actionMonthBilling()
- {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['select_month','roll_month'], 'string'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 获取当前月份
- $current_month = date('Y-m', time());
- // 获取月份
- $check_month = $params['select_month'] ?? $params['roll_month'];// 如果有select_month(选中的月份)优先查询这个,否则查询roll_month(左右滚动的月份)
- $month_data = CommissionMonthBilling::getMonthArr($check_month);
- $month_arr = $month_data['month_arr'];
- //有当月
- $user_id = $this->userwages['id'];
- $where = [
- ['mall_id' => $this->mall_id],
- ['user_id' => $user_id],
- ['month' => $month_arr]
- ];
- $select = 'expenditure_money,income_money,month';
- $list = CommissionMonthBilling::lists(['where' => $where, 'select' => $select, 'index' => 'month']);
- if (in_array($current_month, $month_arr)) {
- $this_month = DateHelper::thisMonth();
- $start_time = $this_month['start'];
- $end_time = $this_month['end'];
- $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
- FROM qimall_commission_log where created_at <={$end_time} and created_at>={$start_time} and user_id ={$user_id} GROUP BY mall_id,user_id,change_type";
- $log_list = \Yii::$app->db->createCommand($sql)->queryAll();
- $current_month_income_money = 0;
- $current_month_expenditure_money = 0;
- foreach ($log_list as $val) {
- if ($val['change_type'] == 'add') {
- $current_month_income_money = $val['SUM3'];
- }
- if ($val['change_type'] == 'sub') {
- $current_month_expenditure_money = $val['SUM3'];
- }
- }
- $list[$current_month] = [
- 'expenditure_money' => $current_month_expenditure_money,
- 'income_money' => $current_month_income_money,
- 'month' => $current_month,
- ];
- }
- $data = [];
- foreach ($month_arr as $val) {
- $temp_arr = explode('-',$val);
- $temp_data = [
- 'expenditure_money' => 0,
- 'income_money' => 0,
- 'month' =>$val,
- ];
- if($temp_arr[1]==1||$temp_arr[1]==12){
- $temp_data['month_str'] = $val;
- }else{
- $temp_data['month_str'] = $temp_arr[1];
- }
- if (isset($list[$val])) {
- $temp_arr = explode('-',$list[$val]['month']);
- if($temp_arr[1]==1||$temp_arr[1]==12){
- $list[$val]['month_str'] = $list[$val]['month'];
- }else{
- $list[$val]['month_str'] = $temp_arr[1];
- }
- $temp_data = $list[$val];
- }
- $data['show_month_arr'][] = $temp_data;
- }
- unset($month_data['month_arr']);
- $data = array_merge($data, $month_data);
- return $this->success('', $data);
- }
- //获取提现信息
- public function actionCashSetting()
- {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['from'], 'required', 'message' => '参数丢失'],
- [['from'], 'in', 'range' => [1, 2]],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 用户已存在,更新用户最新的账号金额信息
- $user = User::findOne(['id' => $this->userwages['id'], 'status' => StatusEnum::ENABLED]);
- if (MallAddons::isInstall($this->mall_id, 'Salary') && Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic.is_external')) {
- UserLogic::updateUser($user->toArray(), 2);
- }
- $user_balance = UserWallet::getOne([['user_id' => $this->userwages['id'], 'status' => 1]], true, [], false, 'balance,commission');
- if ($params['from'] == 1) {//佣金
- $payment = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_income');
- if (!$payment) {
- return $this->error('暂未开启提现功能');
- }
- $isCash = $payment["is_income_cash"];
- $cashType = $payment['cash_type'];
- $cashServiceFee = isset($payment["cash_service_fee"]) ? $payment["cash_service_fee"] : 10;
- $cashIncomeServiceFee = isset($payment["cash_income_service_fee"]) ? $payment["cash_income_service_fee"] : 10;
- $minMoney = $payment['min_money'];
- $maxMoney = $payment['day_max_money'];
- $withdrawal_rule = isset($payment['profit_withdrawal_rule']) ? $payment['profit_withdrawal_rule'] : '手续费费率';
- $userMoney = $user_balance['commission'];
- } else {
- $payment = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance');
- if (!$payment) {
- return $this->error('暂未开启提现功能');
- }
- $isCash = $payment["balance_cash_status"];
- $cashType = $payment['balance_cash_type'];
- $cashServiceFee = isset($payment["balance_cash_service_fee"]) ? $payment["balance_cash_service_fee"] : 10;
- $minMoney = $payment['balance_min_money'];
- $maxMoney = $payment['balance_day_max_money'];
- $withdrawal_rule = isset($payment['profit_withdrawal_rule']) ? $payment['profit_withdrawal_rule'] : '手续费费率';
- $userMoney = $user_balance['balance'];
- }
- $balance_config = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay.balance');
- $pay_password_status = 0;
- if ($balance_config) {
- $balance_config = Json::decode($balance_config);
- $pay_password_status = isset($balance_config["pay_password_status"]) ? $balance_config["pay_password_status"] : 0;
- }
- if (!$isCash) {
- return $this->error('系统未开启提现功能');
- }
- if (!$cashType) {
- return $this->error('系统未设置提现方式');
- }
- $cash__type_name = [];
- $get_system_setting = PlatformSetting::getConfByGroup('system', true);
- if (!empty($cashType)) {
- $cash_type = Json::decode($cashType);
- $cash__type_name = [];
- $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
- $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id]);
- $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way);
- $cash_type_keys = array_keys($all_withdraw);
- if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) {
- $bank_card_list = UserBankCard::getUserCardList($this->userwages['id'], $this->mall_id);
- }
- foreach ($cash_type as $i => $item) {
- if (isset($all_withdraw[$item])) {
- $taxFee = 0;
- $name = '';
- if (isset($all_withdraw[$item])) {
- if (is_array($all_withdraw[$item])) {
- $name = $all_withdraw[$item]['name'] ?? '';
- $taxFee = $all_withdraw[$item]['taxFee'] ?? 0;
- } else {
- $name = $all_withdraw[$item];
- }
- }
- $cash__type_name[$i]['type'] = $item;
- $cash__type_name[$i]['taxFee'] = $taxFee;
- $cash__type_name[$i]['name'] = $name;
- $cash__type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png';
- if ('bank' == $item || 'joinpay' == $item) {
- $cash__type_name[$i]['bank_card_list'] = $bank_card_list;
- }
- }
- }
- }
- $password = User::getOne([['id' => $this->userwages['id']]], true, '', '', 'transaction_password');
- $isTransactionPassword = false;
- $transaction_password = $password['transaction_password'];
- $transaction_password = trim($transaction_password);
- if (!empty($transaction_password)) {
- $isTransactionPassword = true;
- }
- //检测是否需要实名认证
- $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->userwages['id'], 'mall_id' => $this->mall_id, 'type' => 'cash']);
- if ($need_auth === true) {
- //需要先进行实名认证
- return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
- }
- $userWithdrawLog = UserWithdrawLog::getOne([
- ['user_id' => $this->userwages['id']],
- ['type' => ['alipay_tax', 'alipay']]
- ], true, [], 'id desc');
- $aliAccountInfo = [];
- if (!empty($userWithdrawLog)) {
- $extra = json_decode($userWithdrawLog['extra'], true);
- if (!empty($extra)) {
- $aliAccountInfo = [
- 'name' => $extra['name'],
- 'mobile' => $extra['mobile'],
- 'id_card' => $extra['id_card'] ?? '',
- ];
- }
- }
- return $this->success('操作成功', [
- 'notice' => [
- 'content' => '',
- 'icon' => ''
- ],
- 'setting' => [
- 'cash_type_name' => $cash__type_name,
- 'cash_service_fee' => $cashServiceFee,
- 'min_money' => $minMoney,
- 'cash_income_service_fee' => $cashIncomeServiceFee,
- 'day_max_money' => $maxMoney,
- 'withdrawal_rule' => '个人所得税',
- 'pay_password_status' => intval($pay_password_status)
- ],
- 'user_info' => [
- 'income' => $userMoney,
- 'is_transaction_password' => $isTransactionPassword
- ],
- 'ali_account_info' => $aliAccountInfo
- ], ApiStatusEnum::CODE_SUCCESS, 0);
- }
- //提交提现
- public function actionWithdraw()
- {
- $params = \Yii::$app->request->post();
- // 检查商户是否存在
- if (MallAddons::isInstall($this->mall_id, 'Salary')) {
- $merchant = SalaryMerchant::findOne(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($merchant) || empty($merchant->status)) return $this->error('商户不存在或被禁用');
- }
- // 商家认证
- if (MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
- $configs = Yii::$app->services->setting->addons->get($this->mall_id, 'MerchantAuth', 'basic');
- // 开启强制认证并且商家未进行认证
- if ($configs['is_force'] && !MerchantAuthLog::isAuthedByUserId($this->userwages['id'])) {
- return $this->error('商家未认证');
- }
- }
- $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->userwages['id'], 'mall_id' => $this->mall_id, 'type' => 'cash']);
- if ($need_auth === true) {
- //需要先进行实名认证
- return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
- }
- $form = new UserWithdrawLog();
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->userwages['id'];
- $form->attributes = $params;
- $system = Yii::$app->services->setting->platform->get('system');
- $extra['redirect_url'] = ($system['cat_h5_url'] ?? ''). '/#/pages/userWages/index?sign=' .$this->mall['mall_sign'];
- $data = $form->saveRecord($params, $extra);
- if ($data['state'] && !empty($data['data']['cash_id'])) {
- // 提现申请成功,扣减第三方金额
- if (MallAddons::isInstall($this->mall_id, 'Salary') && !empty($data['data']['cash_id'])) {
- if (Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic.is_external')) {
- (new WyaServices($this->mall_id))->changeCommission($this->userwages, [
- 'id' => $data['data']['cash_id'],
- 'num' => $params['price'],
- ], 21);
- } else {
- // 主动推送到第三方平台
- $push_url = Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic.push_url');
- if ($push_url) {
- $logic = (new PushLogic($this->mall_id));
- $salaryUserLogMobile = SalaryUserLog::findOne(['user_id'=>$this->userwages['id']]);
- $cash = UserWithdrawLog::find()->where(['id' => $data['data']['cash_id']])->asArray()->one();
- $logic->changeCommission($push_url, [
- 'mobile' => $this->userwages['mobile'],
- 'muid' => $salaryUserLogMobile['muid'] ?? '',
- 'order_no' => $cash['order_no'],
- 'money' => $cash['num'],
- 'desc' => '申请提现',
- ], 1);
- }
- }
- }
- return $this->success('操作成功', $data['data']);
- } else {
- return $this->error($data['msg']);
- }
- }
- /**
- * 检查是否签约
- * @GetApi(path="actionCheckSign",summary="actionCheckSign")
- * @FormData(key="参数名|中文名", rule="")
- * @FormData(key="参数名|中文名", rule="")
- * @ApiResponse(code="500", template="error")
- * @ApiResponse(code="200", template="success")
- */
- public function actionCheckSign()
- {
- $service = new UserService(['mall_id'=>$this->mall_id]);
- $data = $service->getDefaultSignInfo($this->userwages['id']);
- return $data === false
- ? $this->error($service->getError())
- : $this->success_str('ok', $data);
- }
- /**
- * 去签约
- * @GetApi(path="actionGoToSign",summary="actionGoToSign")
- * @FormData(key="参数名|中文名", rule="")
- * @FormData(key="参数名|中文名", rule="")
- * @ApiResponse(code="500", template="error")
- * @ApiResponse(code="200", template="success")
- */
- public function actionGoToSign(){
- $data = $this->request->post();
- $res = \Yii::$app->services->validate->validate($data,[
- [
- ['mobile','id_card','name','ali_account'], 'required'],
- ],
- [
- 'mobile' => '手机号码',
- 'id_card' => '身份证',
- 'name' => '姓名',
- 'ali_account'=> '支付宝账号',
- ]);
- if( $res === false ) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $service = new UserService(['mall_id'=>$this->mall_id]);
- $url = $service->goToSing( $this->userwages['id'],...array_values($data));
- // 已经签约
- if ( $url === true ) return $this->success('已签约,不需要重复签约',['is_sign'=>true,'url'=>'']);
- // 有错误
- if ( $url === false ) return $this->error('签约失败:'.$service->error);
- // 跳转url
- return $this->success('跳转url进行签约',['is_sign'=>false,'url'=>$url]);
- }
- /**
- * @name:
- * @msg: 绑定银行卡,单纯绑定不签约快捷支付
- * @param {*}
- * @return {*}
- */
- public function actionBindCard()
- {
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $post = \Yii::$app->request->post();
- $rules = [
- [['bank_card_no', 'payer_name', 'bank_name', 'bank_code', 'card_type', 'card_type_name'], 'required'],
- ['bank_card_no', 'string', 'max' => 64],
- [['payer_name', 'bank_name'], 'string', 'max' => 255],
- [['bank_code', 'card_type', 'card_type_name'], 'string', 'max' => 32],
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $bank_card_info = UserBankCard::findONe(['mall_id'=>$this->mall_id,'bank_card_no' => $post['bank_card_no'], 'status' => StatusEnum::ENABLED]);
- if (!empty($bank_card_info)) {
- return $this->error('银行卡已经被绑定');
- }
- $user_id = $this->userwages['id'];
- $post['user_id'] = $user_id;
- $post['card_type'] = strtolower($post['card_type']);
- $model = UserBankCard::setData($this->mall_id, $post, 'bind');
- if (false === $model) return $this->error(UserBankCard::getStaticError());
- return $this->success('操作成功', ['card_id' => $model->id]);
- }
- /**
- * 请求成功统消息格式化处理
- * @Author bing
- * @DateTime 2020-10-27 15:43:16
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param string $msg
- * @param array $data
- * @param [type] $code
- * @return void|mixed
- */
- private function success_str($msg = '操作成功', $data = [], $code = ApiStatusEnum::CODE_SUCCESS)
- {
- if (is_object($data)) $data = ArrayHelper::toArray($data);
- \Yii::$app->controller->asJson(json_decode(json_encode(array(
- 'code' => $code,
- 'msg' => $msg,
- 'data' => $data
- )), true))->send();
- }
- /**
- * 认证列表
- *
- * @return void
- */
- public function actionAuthList()
- {
- $service = new AuthService(['mall_id' => $this->mall_id]);
- return $this->success_str('ok', $service->getUserAuthList($this->userwages['id']));
- }
- /**
- * 设置默认
- *
- * @return void
- */
- public function actionSetDefault()
- {
- $id = $this->request->get('id');
- $service = new AuthService(['mall_id' => $this->mall_id]);
- return $service->setAuthDefault($id)
- ? $this->success('ok')
- : $this->error($service->getError());
- }
- /**
- * 商家认证
- *
- * @return mixed
- */
- public function actionMerchantAuth()
- {
- try {
- // 查询插件
- if (!MallAddons::isInstall($this->mall_id, 'Salary')) {
- return $this->error('插件未安装');
- }
- $model = MerchantAuthLog::getOne(
- [['mall_id' => $this->mall_id], ['user_id' => $this->userwages['id']], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]],
- true, [], 'id desc'
- );
- if (empty($model)) {
- return $this->error('查无数据');
- }
- return $this->success('', $model, ApiStatusEnum::CODE_SUCCESS, 0);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 添加商家认证
- *
- * @return mixed
- */
- public function actionAddMerchantAuth()
- {
- try {
- // 查询插件
- if (!MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
- return $this->error('插件未安装');
- }
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['license', 'idcart_front', 'idcart_back', 'name', 'mobile'], 'required'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->userwages['id'];
- $model = MerchantAuthLog::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id'], 'status' => StatusEnum::ENABLED, 'is_poss' => [0, 1]]);
- if (!empty($model)) {
- if ($model['is_poss'] == 1) {
- return $this->error('认证审核已通过,请勿重复提交');
- }
- if ($model['is_poss'] == 0) {
- return $this->error('已提交认证资料,请等待审核');
- }
- }
- $res = MerchantAuthLog::setData($params);
- if ($res == false) {
- throw new \Exception(MerchantAuthLog::getStaticError());
- }
- return $this->success();
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 商家强制认证
- *
- * @return mixed
- */
- public function actionMerchantAuthConf()
- {
- // 是否强制跳转
- $force = 0;
- // 查询插件
- if (!MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
- return $this->success('ok', compact('force'));
- }
- $configs = Yii::$app->services->setting->addons->get($this->mall_id, 'MerchantAuth', 'basic');
- if ($configs['is_force']) {
- !MerchantAuthLog::isAuthedByUserId($this->userwages['id']) && $force = 1;
- }
- return $this->success('ok', compact('force'));
- }
- }
|