123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace app\models\store;
- use app\models\user\User;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Exception;
- class StoreMgp extends BaseModel
- {
- use ModelTrait;
-
- /**
- * 获取上级及路径
- * @param $no
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getpath($uid=0,$sp_uid=0)
- {
- $no = intval(self::value('max(no)') ?: 0) + 1;
- $no_path = [];$level=1;$p_no=0;
- if($no==1) {
- $no_path = $no;
- $p_no = 0;
- $user_path = $uid;
- }
- else
- {
- if($sp_uid>0)
- {
- $sp = self::where('uid',$sp_uid)->find();
- if($sp['cts']<3)
- {
- $min = $sp;
- }
- else
- {
- $min = self::wherelike('no_path',$sp['no_path'].",%")->where('cts','<',3)->order("level asc,id asc")->find();
- }
- if($min)
- {
- $no_path = $min['no_path'].",".$no;
- $user_path = $min['user_path'].",".$uid;
- $p_no = $min['no'];
- $level = intval($min['level'])+1;
- }
- else
- {
- $no_path = $sp['no_path'].",".$no;
- $user_path = $sp['user_path'].",".$uid;
- $p_no = $sp['no'];
- $level = intval($sp['level'])+1;
- }
- }
- else
- {
- $no_path = $no;
- $user_path = $uid;
- $p_no = $no;
- }
-
- }
- return compact('p_no','no','no_path','user_path','level');
- }
- }
|