StoreMgp.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\models\store;
  3. use app\models\user\User;
  4. use crmeb\basic\BaseModel;
  5. use crmeb\traits\ModelTrait;
  6. use think\Exception;
  7. class StoreMgp extends BaseModel
  8. {
  9. use ModelTrait;
  10. /**
  11. * 获取上级及路径
  12. * @param $no
  13. * @return array
  14. * @throws \think\db\exception\DataNotFoundException
  15. * @throws \think\db\exception\DbException
  16. * @throws \think\db\exception\ModelNotFoundException
  17. */
  18. public static function getpath($uid=0,$sp_uid=0)
  19. {
  20. $no = intval(self::value('max(no)') ?: 0) + 1;
  21. $no_path = [];$level=1;$p_no=0;
  22. if($no==1) {
  23. $no_path = $no;
  24. $p_no = 0;
  25. $user_path = $uid;
  26. }
  27. else
  28. {
  29. if($sp_uid>0)
  30. {
  31. $sp = self::where('uid',$sp_uid)->find();
  32. if($sp['cts']<3)
  33. {
  34. $min = $sp;
  35. }
  36. else
  37. {
  38. $min = self::wherelike('no_path',$sp['no_path'].",%")->where('cts','<',3)->order("level asc,id asc")->find();
  39. }
  40. if($min)
  41. {
  42. $no_path = $min['no_path'].",".$no;
  43. $user_path = $min['user_path'].",".$uid;
  44. $p_no = $min['no'];
  45. $level = intval($min['level'])+1;
  46. }
  47. else
  48. {
  49. $no_path = $sp['no_path'].",".$no;
  50. $user_path = $sp['user_path'].",".$uid;
  51. $p_no = $sp['no'];
  52. $level = intval($sp['level'])+1;
  53. }
  54. }
  55. else
  56. {
  57. $no_path = $no;
  58. $user_path = $uid;
  59. $p_no = $no;
  60. }
  61. }
  62. return compact('p_no','no','no_path','user_path','level');
  63. }
  64. }