SettingController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /****************************************************************
  3. * Author: king -- LiBaoJia
  4. * Date: 5/19/21 10:11 AM
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * IDE: PhpStorm
  8. * User: www.yunzshop.com www.yunzshop.com
  9. * Company: 广州市芸众信息科技有限公司
  10. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务
  11. ****************************************************************/
  12. namespace app\backend\modules\password\controllers;
  13. use app\common\components\BaseController;
  14. use app\common\facades\Setting;
  15. use app\common\modules\shop\ShopConfig;
  16. class SettingController extends BaseController
  17. {
  18. public function index()
  19. {
  20. if ($this->postData()) return $this->store();
  21. return view('password.setting', $this->viewData());
  22. }
  23. /**
  24. * 数据存储
  25. */
  26. private function store()
  27. {
  28. $postData = $this->postData();
  29. $postData['withdraw_verify'] = $this->setWithdrawVerify();
  30. collect($postData)->each(function ($item, $key) {
  31. Setting::set("pay_password.{$key}", $item);
  32. });
  33. return $this->successJson('支付密码设置成功');
  34. }
  35. private function setWithdrawVerify()
  36. {
  37. $withdraw_verify = [];
  38. if (request()->withdraw_verify) {
  39. $data = request()->withdraw_verify;
  40. if (($data['is_phone_verify'] || $data['is_member_export_verify'] || $data['is_commission_export_verify']) && !$data['phone']) {
  41. return $this->errorJson('开启了校验验证,必须设置校验手机号');
  42. }
  43. if ($data['verify_expire'] && intval($data['verify_expire']) > 120) {
  44. return $this->errorJson('校验有效期不得超过120分钟');
  45. }
  46. $set = $this->setData()['withdraw_verify']?:[];
  47. if ($set && $set['phone']) {//之前已设置手机号
  48. if ($data['phone'] && $data['phone'] <> $set['phone']) {//更改了手机号
  49. //验证原手机
  50. $check = app('sms')->checkCode($set['phone'],$data['form2']['verify_code'],'_editWithdraw');
  51. if ($check['status'] == 0) {
  52. return $this->errorJson('原手机验证码验证错误:'.$check['json']);
  53. }
  54. //验证新手机
  55. $check = app('sms')->checkCode($data['phone'],$data['form2']['verify_code_new'],'_editWithdrawNew');
  56. if ($check['status'] == 0) {
  57. return $this->errorJson('新手机验证码验证错误:'.$check['json']);
  58. }
  59. } elseif(($set['is_phone_verify'] && !$data['is_phone_verify']) ||
  60. ($set['is_member_export_verify'] && !$data['is_member_export_verify']) ||
  61. ($set['is_commission_export_verify'] && !$data['is_commission_export_verify'])) {//原先开启的现关闭
  62. //验证手机验证码
  63. if (empty($data['form3']['verify_code'])) {
  64. return $this->errorJson('关闭场景需要验证手机验证码,请填写');
  65. }
  66. $check = app('sms')->checkCode($set['phone'],$data['form3']['verify_code'],'_closeWithdraw');
  67. if ($check['status'] == 0) {
  68. return $this->errorJson('手机验证码验证错误:'.$check['json']);
  69. }
  70. }
  71. } else {//没有设置过手机号
  72. if ($data['phone']) {
  73. $check = app('sms')->checkCode($data['phone'],$data['form1']['verify_code'],'_setWithdraw');
  74. if ($check['status'] == 0) {
  75. return $this->errorJson($check['json']);
  76. }
  77. }
  78. }
  79. $withdraw_verify = [
  80. 'is_set_phone' => $data['phone']?1:0,
  81. 'is_phone_verify' => $data['is_phone_verify']?1:0,
  82. 'is_member_export_verify' => $data['is_member_export_verify']?1:0,
  83. 'is_commission_export_verify' => $data['is_commission_export_verify']?1:0,
  84. 'phone' => $data['phone']?:"",
  85. 'verify_expire' => $data['verify_expire']?:"",
  86. ];
  87. }
  88. return $withdraw_verify;
  89. }
  90. /**
  91. * 提交数据
  92. *
  93. * @return array
  94. */
  95. private function postData()
  96. {
  97. return request()->input('pay_password', []);
  98. }
  99. /**
  100. * view 数据
  101. *
  102. * @return array
  103. */
  104. private function viewData()
  105. {
  106. return [
  107. 'setting' => $this->setData(),
  108. 'condition' => $this->conditionData(),
  109. 'withdraw_verify' => $this->setData()['withdraw_verify'] ?: [],
  110. ];
  111. }
  112. /**
  113. * 设置数据
  114. *
  115. * @return array
  116. */
  117. private function setData()
  118. {
  119. return Setting::getByGroup('pay_password') ?: [];
  120. }
  121. /**
  122. * 自动加载插件配置使用支付密码项
  123. *
  124. * @return array
  125. */
  126. private function conditionData()
  127. {
  128. return ShopConfig::current()->get('password');
  129. }
  130. /**
  131. * 发送验证码
  132. * @return \Illuminate\Http\JsonResponse
  133. */
  134. public function sendVerifyCode()
  135. {
  136. $phone = request()->phone;
  137. switch (request()->type) {
  138. case 1://设置提现手机号获取验证码
  139. $key = '_setWithdraw';
  140. break;
  141. case 2://更改提现手机号获取原手机号验证码
  142. $key = '_editWithdraw';
  143. $set = $this->setData()['withdraw_verify'];
  144. $phone = $set['phone'];
  145. break;
  146. case 3://更改提现手机号获取新手机号验证码
  147. $key = '_editWithdrawNew';
  148. break;
  149. case 4://关闭提现手机号验证获取原手机号验证码
  150. $key = '_closeWithdraw';
  151. $set = $this->setData()['withdraw_verify'];
  152. $phone = $set['phone'];
  153. break;
  154. default:
  155. return $this->errorJson('类型错误');
  156. }
  157. if (!$phone) {
  158. return $this->errorJson('手机号不能为空');
  159. }
  160. $sms = app('sms')->sendWithdrawSet($phone,'86',$key);
  161. if ($sms['status'] == 0) {
  162. return $this->errorJson($sms['json']);
  163. }
  164. return $this->successJson();
  165. }
  166. /**
  167. * 校验验证码
  168. * @return \Illuminate\Http\JsonResponse
  169. */
  170. public function verifyWithdrawCode()
  171. {
  172. $sms = app('sms');
  173. $code = request()->code;
  174. $phone = request()->phone;
  175. if (empty($code)) {
  176. return $this->errorJson('请填写验证码');
  177. }
  178. if (empty($phone) && request()->type <> 3) {
  179. return $this->errorJson('请填写手机号');
  180. }
  181. $set = $this->setData()['withdraw_verify'];
  182. switch (request()->type) {
  183. case 1: //设置提现手机号验证校验验证码
  184. if ($set && $set['phone']) {
  185. return $this->errorJson('使用验证类型错误!');
  186. }
  187. $key = '_setWithdraw';
  188. $check = $sms->checkCode($phone,$code,$key);
  189. if ($check['status'] == 0) {
  190. return $this->errorJson($check['json']);
  191. }
  192. break;
  193. case 2://更改提现手机号验证校验验证码
  194. if (empty($set) || !$set['phone']) {
  195. return $this->errorJson('使用验证类型错误!');
  196. }
  197. $oldCode = request()->oldCode;
  198. if (empty($oldCode)) {
  199. return $this->errorJson('请填写原手机号的验证码');
  200. }
  201. $key = '_editWithdraw';
  202. $check = $sms->checkCode($set['phone'],$oldCode,$key);
  203. if ($check['status'] == 0) {
  204. return $this->errorJson($check['json']);
  205. }
  206. $key = '_editWithdrawNew';
  207. $check = $sms->checkCode($phone,$code,$key);
  208. if ($check['status'] == 0) {
  209. return $this->errorJson($check['json']);
  210. }
  211. break;
  212. case 3://关闭提现手机号验证校验验证码
  213. if (empty($set) || !$set['phone']) {
  214. return $this->errorJson('使用验证类型错误!');
  215. }
  216. $key = '_closeWithdraw';
  217. $check = $sms->checkCode($set['phone'],$code,$key);
  218. if ($check['status'] == 0) {
  219. return $this->errorJson($check['json']);
  220. }
  221. break;
  222. default:
  223. return $this->errorJson('验证码校验类型错误');
  224. }
  225. return $this->successJson('校验通过');
  226. }
  227. }