UserController.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. <?php
  2. namespace api\modules\v1\controllers\userwages;
  3. use addons\AvoidTax\common\models\TaxUserAuth;
  4. use addons\AvoidTax\common\service\AuthService;
  5. use addons\AvoidTax\common\service\UserService;
  6. use addons\AvoidTax\common\service\XinlongService;
  7. use addons\MerchantAuth\common\models\MerchantAuthLog;
  8. use addons\Salary\common\logic\PushLogic;
  9. use addons\Salary\common\logic\UserLogic;
  10. use addons\Salary\common\models\SalaryMerchant;
  11. use addons\Salary\common\models\SalaryUserLog;
  12. use addons\Salary\common\services\WyaServices;
  13. use common\enums\ApiStatusEnum;
  14. use common\enums\StatusEnum;
  15. use common\enums\WithdrawWayEnum;
  16. use common\globals\GlobalInvoke;
  17. use common\helpers\ArrayHelper;
  18. use common\helpers\DateHelper;
  19. use common\helpers\sms\Sms;
  20. use common\models\common\CapitalLog;
  21. use common\models\common\CapitalLogRelation;
  22. use common\models\common\CommissionLog;
  23. use common\models\common\CommissionMonthBilling;
  24. use common\models\common\CommissionYearsBilling;
  25. use common\models\common\PlatformSetting;
  26. use common\models\common\UserBankCard;
  27. use common\models\mall\MallAddons;
  28. use common\models\user\User;
  29. use common\models\user\UserInfo;
  30. use common\models\user\UserWallet;
  31. use common\models\user\UserWithdrawLog;
  32. use yii\helpers\Json;
  33. use Yii;
  34. class UserController extends BaseController
  35. {
  36. /**
  37. * @var string
  38. */
  39. public $modelClass = '';
  40. //首页
  41. public function actionIndex()
  42. {
  43. $user_wallet = UserWallet::getOne([['user_id' => $this->userwages['id']], ['status' => StatusEnum::ENABLED]], true);
  44. $data = [
  45. 'commission_withdrawal' => 0,
  46. 'commission' => 0,
  47. 'frozen_commission' => 0,
  48. 'total_commission' => 0,
  49. 'commission_list' => [],
  50. ];
  51. if (!empty($user_wallet)) {
  52. $data['commission'] = $user_wallet['commission'];
  53. $data['commission_withdrawal'] = $user_wallet['commission_withdrawal'];
  54. $data['frozen_commission'] = $user_wallet['frozen_commission'];
  55. $data['total_commission'] = $user_wallet['total_commission'];
  56. }
  57. $commission_list = CommissionLog::lists([
  58. 'where' => [
  59. ['mall_id' => $this->mall_id],
  60. ['user_id' => $this->userwages['id']]
  61. ],
  62. 'limit' => '3',
  63. 'order' => 'id desc',
  64. 'select' => 'id,change_num,desc,change_type,created_at'
  65. ]);
  66. if (!empty($commission_list)) {
  67. foreach ($commission_list as &$val) {
  68. $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
  69. if ($val['change_type'] == 'add') {
  70. $val['change_type_text'] = '销售收入';
  71. } else {
  72. $val['change_type_text'] = '收入提现';
  73. }
  74. }
  75. $data['commission_list'] = $commission_list;
  76. }
  77. $data['id'] = $this->userwages['id'];
  78. $data['nickname'] = $this->userwages['nickname'];
  79. $data['mobile'] = $this->userwages['mobile'];
  80. $data['avatar_url'] = $this->userwages['avatar_url'];
  81. $config = Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic');
  82. $data['is_eject'] = 0;// 是否已签约,0=否,1=是
  83. $data['is_popup'] = $config['is_sign'] ?? 0;// 是否强制弹窗,0=否,1=是
  84. $data['url'] = '';
  85. $data['accountId'] = '';
  86. $data['flowId'] = '';
  87. $data['pic_url'] = $config['pic_url'] ?? '';
  88. $data['link_text'] = $config['link_text'] ?? '-- 七件事集团技术支持 --';
  89. if(MallAddons::isInstall($this->mall_id, 'AvoidTax')){
  90. try {
  91. $service = new UserService(['mall_id' => $this->mall_id]);
  92. if ($service->checkSign($this->userwages['id'])) {
  93. $data['is_eject'] = 1;
  94. } else {
  95. $data['is_eject'] = 0;
  96. }
  97. } catch (\Exception $e) {
  98. return $this->error('支付宝合规:' . $e->getMessage());
  99. }
  100. }
  101. $data['merchant_status'] = -2;
  102. if (MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
  103. $model = MerchantAuthLog::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id'], 'status' => StatusEnum::ENABLED, 'is_poss' => [0, 1]]);
  104. $data['merchant_status'] = -1;
  105. if (!empty($model)) {
  106. if ($model['is_poss'] == 1) {
  107. $data['merchant_status'] = 1;
  108. }
  109. if ($model['is_poss'] == 0) {
  110. $data['merchant_status'] = 0;
  111. }
  112. }
  113. }
  114. $capital = ['balance' => 'balance', 'score' => 'score', 'redpack' => 'redpack'];
  115. if (!empty($config['is_hide_asset']) && !empty($config['hide_assets'])) {
  116. $hideAssets = json_decode($config['hide_assets'], true) ?: [];
  117. if (in_array('balance', $hideAssets)) {
  118. unset($capital['balance']);
  119. }
  120. if (in_array('score', $hideAssets)) {
  121. unset($capital['score']);
  122. }
  123. if (in_array('redpack', $hideAssets)) {
  124. unset($capital['redpack']);
  125. }
  126. }
  127. $data['capital_list'] = $capital ? UserInfo::getCapital($this->mall_id, $this->user_id, json_encode(array_values($capital))) : [];
  128. return $this->success('成功', $data);
  129. }
  130. /**
  131. * 创建签约
  132. *
  133. * @return void
  134. */
  135. public function actionCreateAccount()
  136. {
  137. $params = \Yii::$app->request->post();
  138. $res = \Yii::$app->services->validate->validate($params, [
  139. [['mobile'], 'required', 'message' => '请填写手机号码'],
  140. [['id_card'], 'required', 'message' => '请填写身份证号码'],
  141. [['name'], 'required', 'message' => '请填写姓名'],
  142. ['mobile', 'match', 'pattern' => '/^1\d{10}/', 'message' => '请输入正确的手机号码'],
  143. ]);
  144. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  145. try {
  146. $service = new UserService(['mall_id' => $this->mall_id]);
  147. // 新龙
  148. if ($service->getConfigService()->isXLApiType()) {
  149. $system = Yii::$app->services->setting->platform->get('system');
  150. $redirect_url = ($system['cat_h5_url'] ?? '') . '/#/pages/userWages/index?sign=' . $this->mall_id;
  151. $res = $service->xlSign(
  152. $this->userwages['id'], $params['name'], $params['mobile'], $params['id_card'], $redirect_url
  153. );
  154. if ($res === true) {
  155. return $this->success('签约成功');
  156. }
  157. if ($res === false) {
  158. return $this->success($service->getError());
  159. }
  160. return $this->success('ok', $res);
  161. }
  162. // 鹿用
  163. if ($service->getConfigService()->isLYApiType()) {
  164. $res = $service->silentSign($this->userwages['id'], $params['name'], $params['mobile'], $params['id_card']);
  165. if ($res === false) {
  166. return $this->error($service->getError());
  167. }
  168. return $this->success('签约成功');
  169. }
  170. } catch (\Exception $e) {
  171. $this->error('申请失败:' . $e->getMessage());
  172. }
  173. }
  174. public function actionRegisterSmsCode()
  175. {
  176. $params = Yii::$app->request->post();
  177. $res = Yii::$app->services->validate->validate($params, [
  178. [['mobile'], 'required', 'message' => '请输入手机号码'],
  179. [['mobile','area_code'], 'integer'],
  180. [['sms_type'], 'string'],
  181. ]);
  182. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  183. $area_code = '';// 初始化区号
  184. $gateways = 'domestic';// 默认国内短信
  185. // 检测是登录并且区号不为空则使用国际短信
  186. if (!empty($this->userwages) && !empty($this->userwages->area_code)) {
  187. $gateways = 'international';
  188. $area_code = $this->userwages->area_code;
  189. }
  190. // 判断是否有区号
  191. if (!empty($params['area_code']) && $params['area_code'] != 86) {
  192. $gateways = 'international';
  193. $area_code = $params['area_code'];
  194. }
  195. $params['sms_type'] = $params['sms_type'] ?: '';
  196. $sms = new Sms($this->mall_id, $gateways);
  197. try {
  198. if ($sms->sendCaptcha($params['mobile'], $area_code,$params['sms_type']) === false) return $this->error('发送失败');
  199. }catch (\Exception $e){
  200. return $this->error($e->getMessage());
  201. }
  202. return $this->success('发送成功');
  203. }
  204. public function actionSetLoginPassword()
  205. {
  206. try {
  207. if (\Yii::$app->request->isPost) {
  208. $params = Yii::$app->request->post();
  209. $res = Yii::$app->services->validate->validate($params, [
  210. [['mobile', 'captcha', 'password', 'confirm_password'], 'required'],
  211. ['mobile', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'],
  212. [['mobile'], 'integer'],
  213. ['password', 'string', 'length' => [6, 11]],
  214. ['confirm_password', 'compare', 'compareAttribute' => 'password', 'message' => '两次密码不一致'],
  215. ]);
  216. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  217. $user = $this->userwages;
  218. if($user['mobile']!=$params['mobile']) return $this->error('请输入绑定的手机号码');
  219. //短信验证码
  220. if (YII_ENV == 'prod') {
  221. if (!Sms::checkValidateCode($params['mobile'], $params['captcha'],Sms::SMS_TYPE_UPDATE_PASS)) return $this->error('验证码不正确');
  222. }
  223. $user = User::findOne(['id'=>$user['id']]);
  224. $user->password = Yii::$app->getSecurity()->generatePasswordHash(trim($params['password']));
  225. if ($user->save() === false) return $this->error(User::getStaticError());
  226. return $this->success('设置成功');
  227. }
  228. } catch (\Exception $e) {
  229. return $this->error($e->getMessage());
  230. }
  231. }
  232. //待结算明细与收益明细
  233. public function actionCommissionList()
  234. {
  235. $params = \Yii::$app->request->get();
  236. $where[] = ['mall_id' => $this->mall_id];
  237. $where[] = ['user_id' => $this->userwages['id']];
  238. if (!empty($params['type']) && $params['type'] == 'frozen') {
  239. CapitalLog::$capitalType = "commission_frozen";
  240. $where[] = ['status' => StatusEnum::DISABLED];
  241. } else {
  242. CapitalLog::$capitalType = "commission";
  243. }
  244. if (!empty($params['date'])) {
  245. $start_time = strtotime($params['date'] . ' 00:00:00');
  246. $end_time = strtotime(date('Ymd', strtotime($params['date'] . '+1 month -1 day')) . ' 23:59:59');
  247. $where[] = ['>=', 'created_at', $start_time];
  248. $where[] = ['<=', 'created_at', $end_time];
  249. }
  250. $params['where'] = $where;
  251. $params['select'] = 'id,change_num,desc,change_type,created_at';
  252. $list = CapitalLog::listPage(array_merge($params, ['order' => 'id desc']));
  253. if (!empty($list['list'])) {
  254. $ids = array_column($list['list'], 'id');
  255. CapitalLogRelation::$capitalType = "commission";
  256. $capitalLog_relation_list = CapitalLogRelation::lists([
  257. 'where' => [
  258. ['log_id' => $ids],
  259. ['source_type' => CapitalLog::$capitalType]
  260. ],
  261. 'index' => 'log_id'
  262. ]);
  263. foreach ($list['list'] as &$val) {
  264. $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
  265. if ($val['change_type'] == 'add') {
  266. $val['change_type_text'] = '销售收入';
  267. } else {
  268. $val['change_type_text'] = '收入提现';
  269. }
  270. if(isset($capitalLog_relation_list[$val['id']])){
  271. $val['desc'] = $capitalLog_relation_list[$val['id']]['describe'];
  272. }
  273. }
  274. }
  275. return $this->success('操作成功', $list);
  276. }
  277. //待结算明细统计
  278. public function actionCommissionTotal()
  279. {
  280. $params = \Yii::$app->request->post();
  281. CapitalLog::$capitalType = "commission_frozen";
  282. if (!empty($params['type']) && $params['type'] == 'frozen') {
  283. CapitalLog::$capitalType = "commission_frozen";
  284. } else {
  285. CapitalLog::$capitalType = "commission";
  286. }
  287. $query = CapitalLog::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id']]);
  288. if (!empty($params['date'])) {
  289. $start_time = strtotime($params['date'] . ' 00:00:00');
  290. $end_time = strtotime(date('Ymd', strtotime($params['date'] . '+1 month -1 day')) . ' 23:59:59');
  291. $query->andWhere(['>=', 'created_at', $start_time]);
  292. $query->andWhere(['<=', 'created_at', $end_time]);
  293. }
  294. if (!empty($params['type']) && $params['type'] == 'frozen') {
  295. CapitalLog::$capitalType = "commission_frozen";
  296. $query->andWhere(['status' => StatusEnum::DISABLED]);
  297. $add_total = $query->sum('change_num');
  298. return $this->success('操作成功', ['add_total' => $add_total, 'sub_total' => 0]);
  299. } else {
  300. $query_copy = clone $query;
  301. $add_total = $query->andWhere(['change_type' => 'add'])->sum('change_num');
  302. $sub_total = $query_copy->andWhere(['change_type' => 'sub'])->sum('change_num');
  303. return $this->success('操作成功', ['add_total' => $add_total ?? 0, 'sub_total' => $sub_total ?? 0]);
  304. }
  305. }
  306. public function actionCashDetail()
  307. {
  308. $user_wallet = UserWallet::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id']]);
  309. $data['commission'] = $user_wallet['commission'] ?? 0;//可用佣金
  310. $start_time = strtotime(date('Y-m-1', time()) . ' 00:00:00');
  311. $end_time = strtotime(date('Y-m-t', time()) . ' 23:59:59');
  312. $where = ['user_id' => $this->userwages['id'], 'mall_id' => $this->mall_id, 'from' => 1, 'status' => [UserWithdrawLog::STATUS_ALREADY_TRANS]];
  313. $commission_withdrawal = UserWithdrawLog::find()->where($where)
  314. ->sum('num');
  315. $data['commission_withdrawal'] = $commission_withdrawal ?? 0;//已提现得总佣金
  316. $month_num = UserWithdrawLog::find()->where($where)
  317. ->andWhere(['>=', 'created_at', $start_time])->andWhere(['<=', 'created_at', $end_time])
  318. ->sum('num');
  319. $monday_time = strtotime(date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)) . ' 00:00:00');
  320. $sunday_time = strtotime(date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) . ' 23:59:59');
  321. $week_num = UserWithdrawLog::find()->where($where)
  322. ->andWhere(['>=', 'created_at', $monday_time])->andWhere(['<=', 'created_at', $sunday_time])
  323. ->sum('num');
  324. $data['month_num'] = $month_num ?? 0;
  325. $data['week_num'] = $week_num ?? 0;
  326. return $this->success('操作成功', $data);
  327. }
  328. //提现明细
  329. public function actionCashList()
  330. {
  331. $params = \Yii::$app->request->get();
  332. $where[] = ['mall_id' => $this->mall_id];
  333. $where[] = ['user_id' => $this->userwages['id']];
  334. $where[] = ['from' => 1];
  335. if (isset($params['status']) && $params['status'] !== '') $where[] = ['status' => $params['status']];
  336. $params['where'] = $where;
  337. $params['select'] = 'id,mall_id,user_id,order_no,num,actual_num,poundage_num,poundage_ratio,content,status,type';
  338. $params['order'] = 'id desc';
  339. $list = UserWithdrawLog::listPage($params);
  340. $list['status_map'] = UserWithdrawLog::$status_msg;
  341. $list['type_map'] = UserWithdrawLog::$type_msg;
  342. return $this->success('操作成功', $list);
  343. }
  344. public function actionWithdrawLogList()
  345. {
  346. $params = \Yii::$app->request->get();
  347. $where[] = ['mall_id' => $this->mall_id];
  348. $where[] = ['user_id' => $this->userwages['id']];
  349. if (isset($params['status'])) {
  350. $where[] = ['=', 'status', $params['status']];
  351. }
  352. $params['where'] = $where;
  353. // $params['select'] = 'id,change_num,desc,change_type,created_at';
  354. $list = UserWithdrawLog::listPage(array_merge($params, ['order' => 'id desc']));
  355. if (!empty($list['list'])) {
  356. foreach ($list['list'] as &$val) {
  357. $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
  358. }
  359. }
  360. return $this->success('操作成功', $list);
  361. }
  362. //账单统计
  363. public function actionBillingStatistics()
  364. {
  365. $params = \Yii::$app->request->post();
  366. $type = $params['type'] ?? 'month';
  367. switch ($type) {
  368. case 'month':
  369. $result = $this->monthBilling($params);
  370. return $this->success('操作成功', $result);
  371. case 'year':
  372. $result = $this->yearBilling($params);
  373. return $this->success('操作成功', $result);
  374. }
  375. }
  376. protected function monthBilling($params)
  377. {
  378. $current_month = date('Y-m', time());
  379. if (!empty($params['month'])) {
  380. $month = $params['month'];
  381. } else {
  382. $month = $current_month;
  383. }
  384. $data = [
  385. 'income_nums' => 0,
  386. 'expenditure_nums' => 0,
  387. 'expenditure_money' => 0,
  388. 'income_money' => 0,
  389. ];
  390. if ($month == $current_month) {
  391. //当前月
  392. $user_id = $this->userwages['id'];
  393. $start_time = strtotime($current_month . '-01 00:00:00');
  394. $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
  395. FROM qimall_commission_log where created_at>={$start_time} and user_id ={$user_id} GROUP BY mall_id,user_id,change_type";
  396. $list = \Yii::$app->db->createCommand($sql)->queryAll();
  397. foreach ($list as $item) {
  398. switch ($item['change_type']) {
  399. case 'add':
  400. $data['income_money'] = $item['SUM3'];
  401. $data['income_nums'] = $item['COUNT4'];
  402. break;
  403. case 'sub':
  404. $data['expenditure_money'] = $item['SUM3'];
  405. $data['expenditure_nums'] = $item['COUNT4'];
  406. break;
  407. }
  408. }
  409. } else {
  410. $where = [
  411. ['mall_id' => $this->mall_id], ['user_id' => $this->userwages['id']], ['month' => $month], ['status' => StatusEnum::ENABLED]];
  412. $res = CommissionMonthBilling::getOne($where, true, [], false, 'income_nums,expenditure_nums,expenditure_money,income_money');
  413. if (!empty($res)) $data = $res;
  414. }
  415. return $data;
  416. }
  417. protected function yearBilling($params)
  418. {
  419. $current_year = date('Y', time());
  420. if (!empty($params['year'])) {
  421. $year = $params['year'];
  422. } else {
  423. $year = $current_year;
  424. }
  425. $data = [
  426. 'income_nums' => 0,
  427. 'expenditure_nums' => 0,
  428. 'expenditure_money' => 0,
  429. 'income_money' => 0,
  430. ];
  431. if ($current_year == $year) {
  432. //当前年
  433. $user_id = $this->userwages['id'];
  434. $month = date('m', time());
  435. $start_time = strtotime($year . '-' . $month . '-01 00:00:00');
  436. $month_arr = [];
  437. $month = intval($month);
  438. for ($i = 1; $i < $month; $i++) {
  439. $tag = '-';
  440. if ($i < 10) {
  441. $tag = $tag . '0';
  442. }
  443. $month_arr[] = $year . $tag . $i;
  444. }
  445. //非当月,除历史统计数据查询
  446. $list = CommissionMonthBilling::lists([
  447. 'where' => [
  448. ['user_id' => $user_id],
  449. ['month' => $month_arr]
  450. ],
  451. 'select' => 'sum(income_money) as income_money,
  452. sum(income_nums) as income_nums,
  453. sum(expenditure_money) as expenditure_money,
  454. sum(expenditure_nums) as expenditure_nums'
  455. ]);
  456. foreach ($list as $val) {
  457. $data['income_money'] += $val['income_money'];
  458. $data['income_nums'] += $val['income_nums'];
  459. $data['expenditure_money'] += $val['expenditure_money'];
  460. $data['expenditure_nums'] += $val['expenditure_nums'];
  461. }
  462. //当月从佣金记录表查询
  463. $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
  464. FROM qimall_commission_log where created_at>={$start_time} and user_id ={$user_id} GROUP BY mall_id,user_id,change_type";
  465. $list = \Yii::$app->db->createCommand($sql)->queryAll();
  466. foreach ($list as $item) {
  467. switch ($item['change_type']) {
  468. case 'add':
  469. $data['income_money'] = bcadd($data['income_money'], $item['SUM3'], 2);
  470. $data['income_nums'] = bcadd($data['income_nums'], $item['COUNT4'], 2);
  471. break;
  472. case 'sub':
  473. $data['expenditure_money'] = bcadd($data['expenditure_money'], $item['SUM3'], 2);
  474. $data['expenditure_nums'] = bcadd($data['expenditure_nums'], $item['COUNT4'], 2);
  475. break;
  476. }
  477. }
  478. } else {
  479. $where = [
  480. ['mall_id' => $this->mall_id], ['user_id' => $this->userwages['id']], ['years' => $year], ['status' => StatusEnum::ENABLED]];
  481. $res = CommissionYearsBilling::getOne($where, true, [], false, 'income_nums,expenditure_nums,expenditure_money,income_money');
  482. if (!empty($res)) $data = $res;
  483. }
  484. return $data;
  485. }
  486. //月账单对比
  487. public function actionBillingContrast()
  488. {
  489. $params = \Yii::$app->request->post();
  490. $current_month = date('Y-m', time());
  491. $month = !empty($params['month']) ? $params['month'] : $current_month;
  492. $tags = '-';
  493. $date1 = explode($tags, $current_month . '-01');
  494. $date2 = explode($tags, $month . '-01');
  495. $cha = abs($date1[0] - $date2[0]) * 12 + ($date1[1] - $date2[1]);
  496. $month_arr = [];
  497. if ($cha <= 3) {
  498. for ($i = 5; $i >= 0; $i--) {
  499. $temp = "-{$i} Months";
  500. $month_arr[] = date("Y-m", strtotime($temp));
  501. }
  502. } else {
  503. $start_i = $cha + 2;
  504. $end_i = $cha - 3;
  505. for ($i = $start_i; $i >= $end_i; $i--) {
  506. $temp = "-{$i} Months";
  507. $month_arr[] = date("Y-m", strtotime($temp));
  508. }
  509. }
  510. //有当月
  511. $user_id = $this->userwages['id'];
  512. $where = [
  513. ['mall_id' => $this->mall_id],
  514. ['user_id' => $user_id],
  515. ['month' => $month_arr]
  516. ];
  517. $select = 'expenditure_money,income_money,month';
  518. $list = CommissionMonthBilling::lists(['where' => $where, 'select' => $select, 'index' => 'month']);
  519. if (in_array($current_month, $month_arr)) {
  520. $this_month = DateHelper::thisMonth();
  521. $start_time = $this_month['start'];
  522. $end_time = $this_month['end'];
  523. $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
  524. 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";
  525. $log_list = \Yii::$app->db->createCommand($sql)->queryAll();
  526. $current_month_income_money = 0;
  527. $current_month_income_nums = 0;
  528. $current_month_expenditure_money = 0;
  529. $current_month_expenditure_nums = 0;
  530. foreach ($log_list as $val) {
  531. if ($val['change_type'] == 'add') {
  532. $current_month_income_money = $val['SUM3'];
  533. // $current_month_income_nums = $val['COUNT4'];
  534. }
  535. if ($val['change_type'] == 'sub') {
  536. $current_month_expenditure_money = $val['SUM3'];
  537. // $current_month_expenditure_nums = $val['COUNT4'];
  538. }
  539. }
  540. $list[$current_month] = [
  541. 'expenditure_money' => $current_month_expenditure_money,
  542. // 'expenditure_nums' => $current_month_expenditure_nums,
  543. 'income_money' => $current_month_income_money,
  544. // 'income_nums' => $current_month_income_nums,
  545. 'month' => $current_month,
  546. ];
  547. }
  548. $data = [];
  549. foreach ($month_arr as $val) {
  550. $is_default = 0;
  551. if ($val == $month) $is_default = 1;
  552. $temp_arr = explode('-',$val);
  553. $temp_data = [
  554. 'expenditure_money' => 0,
  555. 'income_money' => 0,
  556. // 'expenditure_nums' => 0,
  557. // 'income_nums' => 0,
  558. 'month' =>$val,
  559. 'is_default' => $is_default];
  560. if($temp_arr[1]==1||$temp_arr[1]==12){
  561. $temp_data['month_str'] = $val;
  562. }else{
  563. $temp_data['month_str'] = $temp_arr[1];
  564. }
  565. if (isset($list[$val])) {
  566. $temp_arr = explode('-',$list[$val]['month']);
  567. if($temp_arr[1]==1||$temp_arr[1]==12){
  568. $list[$val]['month_str'] = $list[$val]['month'];
  569. }else{
  570. $list[$val]['month_str'] = $temp_arr[1];
  571. }
  572. $list[$val]['is_default'] = $is_default;
  573. $temp_data = $list[$val];
  574. }
  575. $data[] = $temp_data;
  576. }
  577. return $this->success('', $data);
  578. }
  579. /**
  580. * 新月度账单接口
  581. * @Author: lun
  582. * @DateTime: 2023/3/22 0022 10:14
  583. * @Copyright: copyright (c) 2021 广东七件事集团
  584. * @return mixed|void
  585. * @throws \yii\db\Exception
  586. */
  587. public function actionMonthBilling()
  588. {
  589. $params = Yii::$app->request->post();
  590. $res = Yii::$app->services->validate->validate($params, [
  591. [['select_month','roll_month'], 'string'],
  592. ]);
  593. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  594. // 获取当前月份
  595. $current_month = date('Y-m', time());
  596. // 获取月份
  597. $check_month = $params['select_month'] ?? $params['roll_month'];// 如果有select_month(选中的月份)优先查询这个,否则查询roll_month(左右滚动的月份)
  598. $month_data = CommissionMonthBilling::getMonthArr($check_month);
  599. $month_arr = $month_data['month_arr'];
  600. //有当月
  601. $user_id = $this->userwages['id'];
  602. $where = [
  603. ['mall_id' => $this->mall_id],
  604. ['user_id' => $user_id],
  605. ['month' => $month_arr]
  606. ];
  607. $select = 'expenditure_money,income_money,month';
  608. $list = CommissionMonthBilling::lists(['where' => $where, 'select' => $select, 'index' => 'month']);
  609. if (in_array($current_month, $month_arr)) {
  610. $this_month = DateHelper::thisMonth();
  611. $start_time = $this_month['start'];
  612. $end_time = $this_month['end'];
  613. $sql = "SELECT mall_id,user_id,change_type,sum(change_num) as SUM3,count(*) as COUNT4
  614. 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";
  615. $log_list = \Yii::$app->db->createCommand($sql)->queryAll();
  616. $current_month_income_money = 0;
  617. $current_month_expenditure_money = 0;
  618. foreach ($log_list as $val) {
  619. if ($val['change_type'] == 'add') {
  620. $current_month_income_money = $val['SUM3'];
  621. }
  622. if ($val['change_type'] == 'sub') {
  623. $current_month_expenditure_money = $val['SUM3'];
  624. }
  625. }
  626. $list[$current_month] = [
  627. 'expenditure_money' => $current_month_expenditure_money,
  628. 'income_money' => $current_month_income_money,
  629. 'month' => $current_month,
  630. ];
  631. }
  632. $data = [];
  633. foreach ($month_arr as $val) {
  634. $temp_arr = explode('-',$val);
  635. $temp_data = [
  636. 'expenditure_money' => 0,
  637. 'income_money' => 0,
  638. 'month' =>$val,
  639. ];
  640. if($temp_arr[1]==1||$temp_arr[1]==12){
  641. $temp_data['month_str'] = $val;
  642. }else{
  643. $temp_data['month_str'] = $temp_arr[1];
  644. }
  645. if (isset($list[$val])) {
  646. $temp_arr = explode('-',$list[$val]['month']);
  647. if($temp_arr[1]==1||$temp_arr[1]==12){
  648. $list[$val]['month_str'] = $list[$val]['month'];
  649. }else{
  650. $list[$val]['month_str'] = $temp_arr[1];
  651. }
  652. $temp_data = $list[$val];
  653. }
  654. $data['show_month_arr'][] = $temp_data;
  655. }
  656. unset($month_data['month_arr']);
  657. $data = array_merge($data, $month_data);
  658. return $this->success('', $data);
  659. }
  660. //获取提现信息
  661. public function actionCashSetting()
  662. {
  663. $params = \Yii::$app->request->post();
  664. $res = \Yii::$app->services->validate->validate($params, [
  665. [['from'], 'required', 'message' => '参数丢失'],
  666. [['from'], 'in', 'range' => [1, 2]],
  667. ]);
  668. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  669. // 用户已存在,更新用户最新的账号金额信息
  670. $user = User::findOne(['id' => $this->userwages['id'], 'status' => StatusEnum::ENABLED]);
  671. if (MallAddons::isInstall($this->mall_id, 'Salary') && Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic.is_external')) {
  672. UserLogic::updateUser($user->toArray(), 2);
  673. }
  674. $user_balance = UserWallet::getOne([['user_id' => $this->userwages['id'], 'status' => 1]], true, [], false, 'balance,commission');
  675. if ($params['from'] == 1) {//佣金
  676. $payment = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_income');
  677. if (!$payment) {
  678. return $this->error('暂未开启提现功能');
  679. }
  680. $isCash = $payment["is_income_cash"];
  681. $cashType = $payment['cash_type'];
  682. $cashServiceFee = isset($payment["cash_service_fee"]) ? $payment["cash_service_fee"] : 10;
  683. $cashIncomeServiceFee = isset($payment["cash_income_service_fee"]) ? $payment["cash_income_service_fee"] : 10;
  684. $minMoney = $payment['min_money'];
  685. $maxMoney = $payment['day_max_money'];
  686. $withdrawal_rule = isset($payment['profit_withdrawal_rule']) ? $payment['profit_withdrawal_rule'] : '手续费费率';
  687. $userMoney = $user_balance['commission'];
  688. } else {
  689. $payment = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance');
  690. if (!$payment) {
  691. return $this->error('暂未开启提现功能');
  692. }
  693. $isCash = $payment["balance_cash_status"];
  694. $cashType = $payment['balance_cash_type'];
  695. $cashServiceFee = isset($payment["balance_cash_service_fee"]) ? $payment["balance_cash_service_fee"] : 10;
  696. $minMoney = $payment['balance_min_money'];
  697. $maxMoney = $payment['balance_day_max_money'];
  698. $withdrawal_rule = isset($payment['profit_withdrawal_rule']) ? $payment['profit_withdrawal_rule'] : '手续费费率';
  699. $userMoney = $user_balance['balance'];
  700. }
  701. $balance_config = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay.balance');
  702. $pay_password_status = 0;
  703. if ($balance_config) {
  704. $balance_config = Json::decode($balance_config);
  705. $pay_password_status = isset($balance_config["pay_password_status"]) ? $balance_config["pay_password_status"] : 0;
  706. }
  707. if (!$isCash) {
  708. return $this->error('系统未开启提现功能');
  709. }
  710. if (!$cashType) {
  711. return $this->error('系统未设置提现方式');
  712. }
  713. $cash__type_name = [];
  714. $get_system_setting = PlatformSetting::getConfByGroup('system', true);
  715. if (!empty($cashType)) {
  716. $cash_type = Json::decode($cashType);
  717. $cash__type_name = [];
  718. $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
  719. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id]);
  720. $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way);
  721. $cash_type_keys = array_keys($all_withdraw);
  722. if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) {
  723. $bank_card_list = UserBankCard::getUserCardList($this->userwages['id'], $this->mall_id);
  724. }
  725. foreach ($cash_type as $i => $item) {
  726. if (isset($all_withdraw[$item])) {
  727. $taxFee = 0;
  728. $name = '';
  729. if (isset($all_withdraw[$item])) {
  730. if (is_array($all_withdraw[$item])) {
  731. $name = $all_withdraw[$item]['name'] ?? '';
  732. $taxFee = $all_withdraw[$item]['taxFee'] ?? 0;
  733. } else {
  734. $name = $all_withdraw[$item];
  735. }
  736. }
  737. $cash__type_name[$i]['type'] = $item;
  738. $cash__type_name[$i]['taxFee'] = $taxFee;
  739. $cash__type_name[$i]['name'] = $name;
  740. $cash__type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png';
  741. if ('bank' == $item || 'joinpay' == $item) {
  742. $cash__type_name[$i]['bank_card_list'] = $bank_card_list;
  743. }
  744. }
  745. }
  746. }
  747. $password = User::getOne([['id' => $this->userwages['id']]], true, '', '', 'transaction_password');
  748. $isTransactionPassword = false;
  749. $transaction_password = $password['transaction_password'];
  750. $transaction_password = trim($transaction_password);
  751. if (!empty($transaction_password)) {
  752. $isTransactionPassword = true;
  753. }
  754. //检测是否需要实名认证
  755. $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->userwages['id'], 'mall_id' => $this->mall_id, 'type' => 'cash']);
  756. if ($need_auth === true) {
  757. //需要先进行实名认证
  758. return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
  759. }
  760. $userWithdrawLog = UserWithdrawLog::getOne([
  761. ['user_id' => $this->userwages['id']],
  762. ['type' => ['alipay_tax', 'alipay']]
  763. ], true, [], 'id desc');
  764. $aliAccountInfo = [];
  765. if (!empty($userWithdrawLog)) {
  766. $extra = json_decode($userWithdrawLog['extra'], true);
  767. if (!empty($extra)) {
  768. $aliAccountInfo = [
  769. 'name' => $extra['name'],
  770. 'mobile' => $extra['mobile'],
  771. 'id_card' => $extra['id_card'] ?? '',
  772. ];
  773. }
  774. }
  775. return $this->success('操作成功', [
  776. 'notice' => [
  777. 'content' => '',
  778. 'icon' => ''
  779. ],
  780. 'setting' => [
  781. 'cash_type_name' => $cash__type_name,
  782. 'cash_service_fee' => $cashServiceFee,
  783. 'min_money' => $minMoney,
  784. 'cash_income_service_fee' => $cashIncomeServiceFee,
  785. 'day_max_money' => $maxMoney,
  786. 'withdrawal_rule' => '个人所得税',
  787. 'pay_password_status' => intval($pay_password_status)
  788. ],
  789. 'user_info' => [
  790. 'income' => $userMoney,
  791. 'is_transaction_password' => $isTransactionPassword
  792. ],
  793. 'ali_account_info' => $aliAccountInfo
  794. ], ApiStatusEnum::CODE_SUCCESS, 0);
  795. }
  796. //提交提现
  797. public function actionWithdraw()
  798. {
  799. $params = \Yii::$app->request->post();
  800. // 检查商户是否存在
  801. if (MallAddons::isInstall($this->mall_id, 'Salary')) {
  802. $merchant = SalaryMerchant::findOne(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  803. if (empty($merchant) || empty($merchant->status)) return $this->error('商户不存在或被禁用');
  804. }
  805. // 商家认证
  806. if (MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
  807. $configs = Yii::$app->services->setting->addons->get($this->mall_id, 'MerchantAuth', 'basic');
  808. // 开启强制认证并且商家未进行认证
  809. if ($configs['is_force'] && !MerchantAuthLog::isAuthedByUserId($this->userwages['id'])) {
  810. return $this->error('商家未认证');
  811. }
  812. }
  813. $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH, $this->mall_id, ['user_id' => $this->userwages['id'], 'mall_id' => $this->mall_id, 'type' => 'cash']);
  814. if ($need_auth === true) {
  815. //需要先进行实名认证
  816. return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH);
  817. }
  818. $form = new UserWithdrawLog();
  819. $params['mall_id'] = $this->mall_id;
  820. $params['user_id'] = $this->userwages['id'];
  821. $form->attributes = $params;
  822. $system = Yii::$app->services->setting->platform->get('system');
  823. $extra['redirect_url'] = ($system['cat_h5_url'] ?? ''). '/#/pages/userWages/index?sign=' .$this->mall['mall_sign'];
  824. $data = $form->saveRecord($params, $extra);
  825. if ($data['state'] && !empty($data['data']['cash_id'])) {
  826. // 提现申请成功,扣减第三方金额
  827. if (MallAddons::isInstall($this->mall_id, 'Salary') && !empty($data['data']['cash_id'])) {
  828. if (Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic.is_external')) {
  829. (new WyaServices($this->mall_id))->changeCommission($this->userwages, [
  830. 'id' => $data['data']['cash_id'],
  831. 'num' => $params['price'],
  832. ], 21);
  833. } else {
  834. // 主动推送到第三方平台
  835. $push_url = Yii::$app->services->setting->addons->get($this->mall_id, 'Salary', 'basic.push_url');
  836. if ($push_url) {
  837. $logic = (new PushLogic($this->mall_id));
  838. $salaryUserLogMobile = SalaryUserLog::findOne(['user_id'=>$this->userwages['id']]);
  839. $cash = UserWithdrawLog::find()->where(['id' => $data['data']['cash_id']])->asArray()->one();
  840. $logic->changeCommission($push_url, [
  841. 'mobile' => $this->userwages['mobile'],
  842. 'muid' => $salaryUserLogMobile['muid'] ?? '',
  843. 'order_no' => $cash['order_no'],
  844. 'money' => $cash['num'],
  845. 'desc' => '申请提现',
  846. ], 1);
  847. }
  848. }
  849. }
  850. return $this->success('操作成功', $data['data']);
  851. } else {
  852. return $this->error($data['msg']);
  853. }
  854. }
  855. /**
  856. * 检查是否签约
  857. * @GetApi(path="actionCheckSign",summary="actionCheckSign")
  858. * @FormData(key="参数名|中文名", rule="")
  859. * @FormData(key="参数名|中文名", rule="")
  860. * @ApiResponse(code="500", template="error")
  861. * @ApiResponse(code="200", template="success")
  862. */
  863. public function actionCheckSign()
  864. {
  865. $service = new UserService(['mall_id'=>$this->mall_id]);
  866. $data = $service->getDefaultSignInfo($this->userwages['id']);
  867. return $data === false
  868. ? $this->error($service->getError())
  869. : $this->success_str('ok', $data);
  870. }
  871. /**
  872. * 去签约
  873. * @GetApi(path="actionGoToSign",summary="actionGoToSign")
  874. * @FormData(key="参数名|中文名", rule="")
  875. * @FormData(key="参数名|中文名", rule="")
  876. * @ApiResponse(code="500", template="error")
  877. * @ApiResponse(code="200", template="success")
  878. */
  879. public function actionGoToSign(){
  880. $data = $this->request->post();
  881. $res = \Yii::$app->services->validate->validate($data,[
  882. [
  883. ['mobile','id_card','name','ali_account'], 'required'],
  884. ],
  885. [
  886. 'mobile' => '手机号码',
  887. 'id_card' => '身份证',
  888. 'name' => '姓名',
  889. 'ali_account'=> '支付宝账号',
  890. ]);
  891. if( $res === false ) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  892. $service = new UserService(['mall_id'=>$this->mall_id]);
  893. $url = $service->goToSing( $this->userwages['id'],...array_values($data));
  894. // 已经签约
  895. if ( $url === true ) return $this->success('已签约,不需要重复签约',['is_sign'=>true,'url'=>'']);
  896. // 有错误
  897. if ( $url === false ) return $this->error('签约失败:'.$service->error);
  898. // 跳转url
  899. return $this->success('跳转url进行签约',['is_sign'=>false,'url'=>$url]);
  900. }
  901. /**
  902. * @name:
  903. * @msg: 绑定银行卡,单纯绑定不签约快捷支付
  904. * @param {*}
  905. * @return {*}
  906. */
  907. public function actionBindCard()
  908. {
  909. if (!\Yii::$app->request->isPost) {
  910. return $this->error('请求方式错误');
  911. }
  912. $post = \Yii::$app->request->post();
  913. $rules = [
  914. [['bank_card_no', 'payer_name', 'bank_name', 'bank_code', 'card_type', 'card_type_name'], 'required'],
  915. ['bank_card_no', 'string', 'max' => 64],
  916. [['payer_name', 'bank_name'], 'string', 'max' => 255],
  917. [['bank_code', 'card_type', 'card_type_name'], 'string', 'max' => 32],
  918. ];
  919. $res = \Yii::$app->services->validate->validate($post, $rules);
  920. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  921. $bank_card_info = UserBankCard::findONe(['mall_id'=>$this->mall_id,'bank_card_no' => $post['bank_card_no'], 'status' => StatusEnum::ENABLED]);
  922. if (!empty($bank_card_info)) {
  923. return $this->error('银行卡已经被绑定');
  924. }
  925. $user_id = $this->userwages['id'];
  926. $post['user_id'] = $user_id;
  927. $post['card_type'] = strtolower($post['card_type']);
  928. $model = UserBankCard::setData($this->mall_id, $post, 'bind');
  929. if (false === $model) return $this->error(UserBankCard::getStaticError());
  930. return $this->success('操作成功', ['card_id' => $model->id]);
  931. }
  932. /**
  933. * 请求成功统消息格式化处理
  934. * @Author bing
  935. * @DateTime 2020-10-27 15:43:16
  936. * @copyright: Copyright (c) 2020 广东七件事集团
  937. * @param string $msg
  938. * @param array $data
  939. * @param [type] $code
  940. * @return void|mixed
  941. */
  942. private function success_str($msg = '操作成功', $data = [], $code = ApiStatusEnum::CODE_SUCCESS)
  943. {
  944. if (is_object($data)) $data = ArrayHelper::toArray($data);
  945. \Yii::$app->controller->asJson(json_decode(json_encode(array(
  946. 'code' => $code,
  947. 'msg' => $msg,
  948. 'data' => $data
  949. )), true))->send();
  950. }
  951. /**
  952. * 认证列表
  953. *
  954. * @return void
  955. */
  956. public function actionAuthList()
  957. {
  958. $service = new AuthService(['mall_id' => $this->mall_id]);
  959. return $this->success_str('ok', $service->getUserAuthList($this->userwages['id']));
  960. }
  961. /**
  962. * 设置默认
  963. *
  964. * @return void
  965. */
  966. public function actionSetDefault()
  967. {
  968. $id = $this->request->get('id');
  969. $service = new AuthService(['mall_id' => $this->mall_id]);
  970. return $service->setAuthDefault($id)
  971. ? $this->success('ok')
  972. : $this->error($service->getError());
  973. }
  974. /**
  975. * 商家认证
  976. *
  977. * @return mixed
  978. */
  979. public function actionMerchantAuth()
  980. {
  981. try {
  982. // 查询插件
  983. if (!MallAddons::isInstall($this->mall_id, 'Salary')) {
  984. return $this->error('插件未安装');
  985. }
  986. $model = MerchantAuthLog::getOne(
  987. [['mall_id' => $this->mall_id], ['user_id' => $this->userwages['id']], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]],
  988. true, [], 'id desc'
  989. );
  990. if (empty($model)) {
  991. return $this->error('查无数据');
  992. }
  993. return $this->success('', $model, ApiStatusEnum::CODE_SUCCESS, 0);
  994. } catch (\Exception $e) {
  995. return $this->error($e->getMessage());
  996. }
  997. }
  998. /**
  999. * 添加商家认证
  1000. *
  1001. * @return mixed
  1002. */
  1003. public function actionAddMerchantAuth()
  1004. {
  1005. try {
  1006. // 查询插件
  1007. if (!MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
  1008. return $this->error('插件未安装');
  1009. }
  1010. $params = Yii::$app->request->post();
  1011. $res = Yii::$app->services->validate->validate($params, [
  1012. [['license', 'idcart_front', 'idcart_back', 'name', 'mobile'], 'required'],
  1013. ]);
  1014. if ($res === false) {
  1015. return $this->error(Yii::$app->services->validate->getErrorMessage());
  1016. }
  1017. $params['mall_id'] = $this->mall_id;
  1018. $params['user_id'] = $this->userwages['id'];
  1019. $model = MerchantAuthLog::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->userwages['id'], 'status' => StatusEnum::ENABLED, 'is_poss' => [0, 1]]);
  1020. if (!empty($model)) {
  1021. if ($model['is_poss'] == 1) {
  1022. return $this->error('认证审核已通过,请勿重复提交');
  1023. }
  1024. if ($model['is_poss'] == 0) {
  1025. return $this->error('已提交认证资料,请等待审核');
  1026. }
  1027. }
  1028. $res = MerchantAuthLog::setData($params);
  1029. if ($res == false) {
  1030. throw new \Exception(MerchantAuthLog::getStaticError());
  1031. }
  1032. return $this->success();
  1033. } catch (\Exception $e) {
  1034. return $this->error($e->getMessage());
  1035. }
  1036. }
  1037. /**
  1038. * 商家强制认证
  1039. *
  1040. * @return mixed
  1041. */
  1042. public function actionMerchantAuthConf()
  1043. {
  1044. // 是否强制跳转
  1045. $force = 0;
  1046. // 查询插件
  1047. if (!MallAddons::isInstall($this->mall_id, 'MerchantAuth')) {
  1048. return $this->success('ok', compact('force'));
  1049. }
  1050. $configs = Yii::$app->services->setting->addons->get($this->mall_id, 'MerchantAuth', 'basic');
  1051. if ($configs['is_force']) {
  1052. !MerchantAuthLog::isAuthedByUserId($this->userwages['id']) && $force = 1;
  1053. }
  1054. return $this->success('ok', compact('force'));
  1055. }
  1056. }