CommonOrder.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models\common;
  8. use app\models\User;
  9. use app\modules\client\models\v1\BindForm;
  10. use yii\base\Model;
  11. class CommonOrder
  12. {
  13. /**
  14. * 持续更新...
  15. * 下单前的检测
  16. */
  17. public static function checkOrder($other = [])
  18. {
  19. $user = get_user();
  20. if ($user->blacklist) {
  21. return [
  22. 'code' => 1,
  23. 'msg' => '无法下单'
  24. ];
  25. }
  26. if (isset($other['mobile']) && $other['mobile']) {
  27. if (!preg_match("/^1\d{10}$/", $other['mobile'])) {
  28. return [
  29. 'code' => 1,
  30. 'msg' => '请输入正确的手机号111'
  31. ];
  32. }
  33. }
  34. }
  35. /**
  36. * 分销 保存上级的ID(用于先成为上下级,再成为分销商)
  37. * @param $parentId
  38. * @return static
  39. */
  40. public static function saveParentId($parentId)
  41. {
  42. if (!$parentId) {
  43. return;
  44. }
  45. // 父级用户不存在
  46. $parentUser = User::findOne($parentId);
  47. if (!$parentUser) {
  48. return;
  49. }
  50. $user = get_user();
  51. if ($user) {
  52. $form = new BindForm();
  53. $form->store_id = get_store_id();
  54. $form->user_id = get_user_id();
  55. $form->parent_id = $parentId;
  56. $form->condition = 1;
  57. $form->save();
  58. // $user->parent_user_id = $parentId;
  59. // $user->save();
  60. }
  61. return $user;
  62. }
  63. }