Synthesis.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\UserModel;
  5. use app\common\model\UserPathModel;
  6. use app\common\model\Synthesis as SynthesisModel;
  7. use fast\Action;
  8. use fast\Asset;
  9. use fast\Http;
  10. use think\Db;
  11. use think\Log;
  12. //合成管理
  13. class Synthesis extends Api
  14. {
  15. public function list(SynthesisModel $synthesis)
  16. {
  17. $list = $synthesis->alias('a')
  18. ->join("product_list b", "a.product_id = b.id", "left")
  19. ->join("user u", "a.user_id = u.id", "left")
  20. ->join("products d", "b.type_id = d.id", "left")
  21. ->join("product_area dr", "dr.id = a.area_id", "left") //地区
  22. ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,price,u.nickname,d.'.$this->lan.'_title as title,dr.address')
  23. ->where('a.status', $synthesis::Normal)
  24. ->where($map)
  25. ->order($order)
  26. ->paginate($this->pageSize);
  27. $this->success('', $list);
  28. }
  29. /*
  30. * 更新上级
  31. */
  32. public function change_parent()
  33. {
  34. //3.更新主表会员上级
  35. dump('重建网体');
  36. $user_list = Db::table('user_1')
  37. ->order('distance')
  38. ->select();
  39. $i = 0;
  40. foreach ($user_list as $user){
  41. $parent_info = (new UserModel())
  42. ->where('address', $user['parent_address'])
  43. ->find();
  44. if(!empty($parent_info)){
  45. $is = Db::table('user')
  46. ->where('id', $user['id'])
  47. ->update([
  48. 'parent_id' => $parent_info['id']
  49. ]);
  50. //删除网体
  51. (new UserPathModel())
  52. ->where('user_id', $user['id'])
  53. ->delete();
  54. // 创建网体
  55. (new UserPathModel())->createPath($user['id'], $parent_info['id']);
  56. $i++;
  57. } else{
  58. dump($user['id'] . '--无上级');
  59. }
  60. }
  61. halt($i);
  62. }
  63. }