12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace app\common\model;
- use think\Db;
- use tools\Phptree;
- class UserConveyCate extends Base
- {
- // 更新用户常用运送类型
- public function updateCate($userId,$conveyCateId){
- $info = Db::name('user_convey_cate')->where('user_id',$userId)->where('convey_cate_id',$conveyCateId)->find();
- if($info){
- $ret = Db::name('user_convey_cate')->where('id',$info['id'])->setInc('nums',1);
- }else{
- $ret = Db::name('user_convey_cate')->insert([
- 'user_id' => $userId,
- 'convey_cate_id' => $conveyCateId,
- 'nums' => 1
- ]);
- }
- return $ret?true:false;
- }
- // 获取用户常用运送类型
- public function getUserCates($userId){
- $lists = Db::name('user_convey_cate')->where('user_id',$userId)->order('nums desc,id asc')->column('convey_cate_id');
- return $lists?$lists:[];
- }
- public function sortUserCates($lists,$userId){
- $cates = $this->getUserCates($userId);
- $cates = $cates?array_unique($cates):[];
- if(!$cates){
- return $lists;
- }
- $list1 = [];
- foreach ($cates as $k=>$v){
- foreach ($lists as $k1=>$v1){
- if($v1['id'] == $v){
- $list1[] = $v1;
- break;
- }
- }
- }
- foreach ($lists as $k=>$v){
- if(!in_array($v['id'],$cates)){
- $list1[] = $v;
- }
- }
- return $list1;
- }
- }
|