UpdateController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /****************************************************************
  3. * Author: king -- LiBaoJia
  4. * Date: 5/19/21 3:41 PM
  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\services\password\PasswordService;
  15. use app\frontend\models\MemberShopInfo;
  16. class UpdateController extends BaseController
  17. {
  18. public function index()
  19. {
  20. $this->validator();
  21. return $this->update() ? $this->successJson() : $this->errorJson();
  22. }
  23. private function update()
  24. {
  25. $data = (new PasswordService())->create(trim(request()->password));
  26. return MemberShopInfo::where('member_id', request()->member_id)->update(['pay_password' => $data['password'], 'salt' => $data['salt']]);
  27. }
  28. /**
  29. * 验证数据
  30. */
  31. public function validator()
  32. {
  33. $validator = $this->getValidationFactory()->make(request()->all(), $this->rules(), $this->messages(), $this->attributeNames());
  34. if ($validator->fails()) $this->errorJson($validator->errors()->first());
  35. }
  36. /**
  37. * 字段规则
  38. *
  39. * @return array
  40. */
  41. public function rules()
  42. {
  43. if((new PasswordService())->masterSwitch()) {
  44. return [
  45. 'member_id' => 'required|integer|min:0',
  46. // 'password' => 'required|min:6|max:6|regex:/^[0-9]*$/|same:confirmed',
  47. 'confirmed' => 'required|same:password'
  48. ];
  49. }
  50. return [
  51. 'member_id' => 'required|integer|min:0',
  52. 'password' => 'required|min:6|max:6|regex:/^[0-9]*$/|same:confirmed',
  53. 'confirmed' => 'required|same:password'
  54. ];
  55. }
  56. /**
  57. * 自定义消息
  58. *
  59. * @return array
  60. */
  61. private function messages()
  62. {
  63. return [
  64. 'same' => '两次输入不一致',
  65. ];
  66. }
  67. /**
  68. * 自定义名称
  69. *
  70. * @return array
  71. */
  72. public function attributeNames()
  73. {
  74. return [
  75. 'password' => '密码',
  76. 'confirmed' => '确认密码',
  77. ];
  78. }
  79. }