CashAccountsController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/20
  6. * Time: 上午11:36
  7. */
  8. namespace App\Http\Controllers\Channel\Finance;
  9. use App\Http\Controllers\Channel\Finance\Transformers\CashAccountTransformer;
  10. use App\Modules\Channel\Services\ChannelService;
  11. use App\Modules\Channel\Services\ChannelUserService;
  12. use App\Modules\Finance\Services\BankService;
  13. use App\Modules\Finance\Services\CashAccountService;
  14. use Illuminate\Http\Request;
  15. use Cache;
  16. use Redis;
  17. use App\Libs\SMS;
  18. use Log;
  19. use App\Libs\AliSMS;
  20. class CashAccountsController extends BaseController
  21. {
  22. /**
  23. * @apiDefine Finance 结算提现模块
  24. */
  25. /**
  26. * @apiVersion 1.0.0
  27. * @apiDescription 获取银行账号
  28. * @api {GET} getCashAccount 获取银行账号
  29. * @apiGroup Finance
  30. * @apiName getCashAccount
  31. * @apiSuccess {String} account_name 姓名.
  32. * @apiSuccess {String} identity_card 身份证号码.
  33. * @apiSuccess {String} card_number 银行卡号码.
  34. * @apiSuccess {String} account_bank 开户支行名称.
  35. * @apiSuccess {Number} bank_id 银行ID.
  36. * @apiSuccess {String} bank 交易银行.
  37. * @apiSuccess {String} phone 电话号码.
  38. * @apiSuccess {String} province 省份.
  39. * @apiSuccess {Number} status 省份.状态; -1:禁止编辑; 0:默认可编辑
  40. * @apiSuccess {Number} is_company 0:对私账户; 1:对公账户
  41. * @apiSuccessExample {json} Success-Response:
  42. *
  43. * {
  44. * "code": 0,
  45. * "msg": "",
  46. * "data":
  47. * {
  48. * "account_bank": "钱江支行",
  49. * "account_name": "宋晓",
  50. * "bank_id": 1,
  51. * "bank": "杭州银行",
  52. * "card_number": "6222520177654916",
  53. * "identity_card": "33038119930901821X",
  54. * "province": "北京市",
  55. * "status": -1,
  56. * "phone": "13688998899",
  57. * "is_company": 0,
  58. * "updated_time": "2017-11-20 14:54:50"
  59. * }
  60. * }
  61. */
  62. function get_cashAccount(Request $request) {
  63. $distribution_channel_id = $this->getChannelId();
  64. $distribution_channel_name = $this->getChannelName();
  65. $distribution_channel_name = '';
  66. $cashAccount = CashAccountService::getCashAccountSingle($distribution_channel_id);
  67. return response()->item(new CashAccountTransformer(), $cashAccount);
  68. }
  69. /**
  70. * @apiVersion 1.0.0
  71. * @apiDescription 添加更新银行账号
  72. * @api {POST} addCashAccount 添加银行账号
  73. * @apiGroup Finance
  74. * @apiName addCashAccount
  75. * @apiParam {Number} [is_company] 0:对私账户; 1:对公账户
  76. * @apiParam {Number} bank_id 银行ID.
  77. * @apiParam {String} account_bank 开户支行名称.
  78. * @apiParam {String} account_name 对私账户:开户人名称; 对公账户:持卡人名称
  79. * @apiParam {String} card_number 银行卡号码.
  80. * @apiParam {String} [phone] 电话号码.
  81. * @apiParam {String} [identity_card] 对私账户:开户人身份证号码; 对公账户:持卡人身份证号码
  82. * @apiParam {String} [province] 省份.
  83. * @apiParam {String} [sms_code] 验证码,修改的时候必传.
  84. *
  85. * @apiSuccess {String} account_name 姓名.
  86. * @apiSuccess {String} identity_card 身份证号码.
  87. * @apiSuccess {String} card_number 银行卡号码.
  88. * @apiSuccess {String} account_bank 开户支行名称.
  89. * @apiSuccess {Number} bank_id 银行ID.
  90. * @apiSuccess {String} bank 交易银行.
  91. * @apiSuccess {String} phone 电话号码.
  92. * @apiSuccess {String} province 省份.
  93. * @apiSuccess {Number} status 省份.状态; -1:禁止编辑; 0:默认可编辑
  94. * @apiSuccess {Number} is_company 0:对私账户; 1:对公账户
  95. * @apiSuccessExample {json} Success-Response:
  96. *
  97. * {
  98. * "code": 0,
  99. * "msg": "",
  100. * "data":
  101. * {
  102. * "account_bank": "钱江支行",
  103. * "account_name": "宋晓",
  104. * "bank_id": 1,
  105. * "bank": "杭州银行",
  106. * "card_number": "6222520177654916",
  107. * "identity_card": "33038119930901821X",
  108. * "province": "北京市",
  109. * "status": -1,
  110. * "phone": "13688998899",
  111. * "is_company": 0,
  112. * "updated_time": "2017-11-20 14:54:50"
  113. * }
  114. * }
  115. */
  116. function add_cashAccount(Request $request) {
  117. $distribution_channel_id = $this->getChannelId();
  118. $channel_id = $distribution_channel_id;
  119. $distribution_channel_name = $this->getChannelName();
  120. $distribution_channel_name = '';
  121. if(empty($distribution_channel_id)) {
  122. return response()->error("PARAM_EMPTY");
  123. }
  124. $account_name = $request->has('account_name') ? $request->input('account_name') : '';
  125. if(empty($account_name)) {
  126. return response()->error("PARAM_EMPTY");
  127. }
  128. $identity_card = $request->has('identity_card') ? $request->input('identity_card') : '';
  129. // if(empty($identity_card)) {
  130. // return response()->error("PARAM_EMPTY");
  131. // }
  132. $card_number = $request->has('card_number') ? $request->input('card_number') : '';
  133. if(empty($card_number)) {
  134. return response()->error("PARAM_EMPTY");
  135. }
  136. $account_bank = $request->has('account_bank') ? $request->input('account_bank') : '';
  137. // if(empty($account_bank)) {
  138. // return response()->error("PARAM_EMPTY");
  139. // }
  140. $bank_id = $request->has('bank_id') ? $request->input('bank_id') : '';
  141. if(!is_numeric($bank_id)) {
  142. return response()->error("PARAM_ERROR");
  143. }
  144. $bankModel = BankService::getBankSingle($bank_id);
  145. if(empty($bankModel)) {
  146. return response()->error("PARAM_ERROR");
  147. }
  148. $is_company = $request->has('is_company') ? $request->input('is_company') : '';
  149. $bank = $request->has('bank') ? $request->input('bank') : '';
  150. if(empty($bank)) {
  151. $bank = $bankModel['name'];
  152. }
  153. $province = $request->has('province') ? $request->input('province') : '';
  154. $phone = $request->has('phone') ? $request->input('phone') : '';
  155. $cashAccount = CashAccountService::getCashAccountSingle($distribution_channel_id);
  156. if(empty($cashAccount)) {
  157. $cashAccount = CashAccountService::addCashAccount($distribution_channel_id, $account_name, $identity_card, $card_number, $account_bank, $bank_id, $bank, $province, $is_company, $phone);
  158. } else {
  159. $channel = ChannelService::getById($distribution_channel_id);
  160. if(!$channel) {
  161. return response()->error('PARAM_ERROR');
  162. }
  163. $channelUser = ChannelUserService::getById($channel->channel_user_id);
  164. if(!$channelUser) {
  165. return response()->error('PARAM_ERROR');
  166. }
  167. $phoneCodeNumber = $channelUser->phone;
  168. $phoneCode = Redis::get('sms_'.$channel_id."_".$phoneCodeNumber);
  169. if(!$phoneCode) {
  170. $phoneCode = Cache::get('sms_'.$channel_id."_".$phoneCodeNumber);
  171. }
  172. $exist_sms_code = $phoneCode;
  173. $sms_code = $request->has('sms_code') ? $request->input('sms_code') : '';
  174. Log::info("======修改渠道提现信息验证码=====[".'sms_'.$channel_id."_".$phoneCodeNumber."_".$exist_sms_code."]======输入验证码 [ ".$sms_code ." =====".date("y-m-d H:i:s"."\n"));
  175. if(empty($exist_sms_code) || empty($sms_code)) {
  176. return response()->error('PHONE_CODE_ERROR');
  177. }
  178. if($sms_code != $exist_sms_code) {
  179. return response()->error('VERIFY_CODE_ERROR');
  180. }
  181. $cashAccount = CashAccountService::updateCashAccount($distribution_channel_id, $account_name, $identity_card, $card_number, $account_bank, $bank_id, $bank, $province, $is_company, $phone);
  182. Cache::forget('sms_'.$channel_id."_".$phoneCodeNumber);
  183. Redis::del('sms_'.$channel_id."_".$phoneCodeNumber);
  184. // if(CashAccountService::isEditCashAccount($distribution_channel_id)) {
  185. // //-1 禁止修改
  186. // return response()->error("FORBID_CHANGE");
  187. // } else {
  188. // }
  189. }
  190. return response()->item(new CashAccountTransformer(), $cashAccount);
  191. }
  192. /**
  193. * @apiVersion 1.0.0
  194. * @apiDescription 获取修改银行账号信息验证码
  195. * @api {GET} getCashAccountSms 获取修改银行账号信息验证码
  196. * @apiGroup Finance
  197. * @apiName getCashAccountSms
  198. * @apiSuccessExample {json} Success-Response:
  199. *
  200. * {
  201. * "code": 0,
  202. * "msg": "",
  203. * "data":[]
  204. * }
  205. */
  206. function getCashAccountSms(Request $request) {
  207. $channel_id = $this->getChannelId();
  208. $userId = $this->getChannelUserId();
  209. if($userId) {
  210. $user = ChannelUserService::getById($userId);
  211. if($user) {
  212. $phone = $user->phone;
  213. if(Cache::get('sms_'.$channel_id."_".$phone)) {
  214. return response()->error('SMS_GET_TOO_OFTEN');
  215. }
  216. $code = rand(1000,9999);
  217. $request->session()->put('sms_code', $code);
  218. Cache::put('sms_'.$channel_id."_".$phone, $code, 10);
  219. Log::info("======修改渠道提现信息验证码=====[".'sms_'.$channel_id."_".$phone."_".$code."]===========".date("y-m-d H:i:s"."\n"));
  220. Redis::setex('sms_'.$channel_id."_".$phone, 10 * 60, $code);
  221. $param = array('code'=>$code);
  222. if(AliSMS::send($phone,'update_withdraw_cash',$param)){
  223. return response()->success();
  224. }else{
  225. return response()->error('SMS_SEND_ERROR');
  226. }
  227. }
  228. }
  229. return response()->error('SMS_SEND_ERROR');
  230. }
  231. }