UserControllerCopy.php 47 KB

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