FavoriteListForm.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\models;
  8. use app\models\Admin;
  9. use app\models\Favorite;
  10. use app\models\Goods;
  11. use app\models\Mch;
  12. use app\models\SaasUser;
  13. use app\models\Store;
  14. use app\models\Cat;
  15. use app\models\WechatConfig;
  16. use yii\base\Model;
  17. use yii\data\Pagination;
  18. use yii\helpers\VarDumper;
  19. use app\modules\client\models\ApiModel;
  20. class FavoriteListForm extends ApiModel
  21. {
  22. public $store_id;
  23. public $user_id;
  24. public $saas_id;
  25. public $page;
  26. public $limit;
  27. public $type;
  28. public function rules()
  29. {
  30. return [
  31. [['type'], 'default', 'value' => 0],
  32. ['type', 'in', 'range' => [Favorite::FAVORITE_GOODS, Favorite::FAVORITE_SHOP]],
  33. [['page', 'limit',], 'integer',],
  34. [['page'], 'default', 'value' => 1],
  35. [['limit'], 'default', 'value' => 20],
  36. ];
  37. }
  38. public function league_search($saas_user_id)
  39. {
  40. $admin = Admin::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0, 'type' => 'store']);
  41. $store = Store::findOne($admin->type_id);
  42. if($store){
  43. return [
  44. 'code' => 0,
  45. 'data' => $store->league_price,
  46. 'msg' => '查找成功'
  47. ];
  48. }else{
  49. return [
  50. 'code' => 1,
  51. 'msg' => '该账户不是商城管理员'
  52. ];
  53. }
  54. }
  55. public function search()
  56. {
  57. if (!$this->validate()) {
  58. return [
  59. 'code' => 1,
  60. 'msg' => $this->getErrorSummary(false)[0]
  61. ];
  62. }
  63. // 暂无商品收藏列表
  64. // if ($this->type == Favorite::FAVORITE_GOODS) {
  65. // $query = Favorite::find()->where(['store_id' => $this->store_id, 'type' => Favorite::FAVORITE_GOODS, 'is_delete' => 0, 'user_id' => $this->user_id]);
  66. // $count = $query->count();
  67. // $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  68. // $list = $query->select('*')->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
  69. // $new_list = [];
  70. // foreach ($list as $i => $favorite) {
  71. // $goods = Goods::findOne(['store_id' => $this->store_id, 'is_delete' => 0, 'status' => Goods::STATUS_NORMAL, 'id' => $favorite['goods_id']]);
  72. // if (!$goods) {
  73. // continue;
  74. // }
  75. // if ($goods->is_negotiable) {
  76. // $goods->price = Goods::GOODS_NEGOTIABLE;
  77. // }
  78. // $new_list[] = (object)[
  79. // 'id' => $favorite['id'],
  80. // 'goods_id' => $goods->id,
  81. // 'name' => $goods->name,
  82. // 'price' => $goods->price,
  83. // 'goods_pic' => $goods->getGoodsPic(0)->pic_url,
  84. // 'is_negotiable' => $goods->is_negotiable,
  85. // ];
  86. // }
  87. // return [
  88. // 'code' => 0,
  89. // 'data' => (object)[
  90. // 'row_count' => $count,
  91. // 'page_count' => $pagination->pageCount,
  92. // 'list' => $new_list,
  93. // ],
  94. // ];
  95. // }
  96. if ($this->type == Favorite::FAVORITE_SHOP) {
  97. $query = Favorite::find()->where(['type' => Favorite::FAVORITE_SHOP, 'is_delete' => 0, 'saas_id' => $this->saas_id]);
  98. $count = $query->count();
  99. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  100. $list = $query->select('*')->limit($pagination->limit)->offset($pagination->offset)->orderBy('created_at DESC')->asArray()->all();
  101. $new_list = [];
  102. foreach ($list as $key => $shop) {
  103. //$mch = Mch::find()->where(['id' => $shop['goods_id'], 'store_id' => $this->store_id, 'is_delete' => 0, 'is_open' => 1, 'is_lock' => 0])->one();
  104. //$store = Store::find()->where(['id' =>$shop['store_id'], 'is_delete' => 0])->one();
  105. $storeInfo = Store::find()->alias('s')->where(['s.id'=>$shop['store_id'],'s.is_delete'=>0])->select('s.id,s.name,s.logo,s.address,s.category_id,s.sales,s.rank,s.per_spend,s.coordinate,s.business_model')->asArray()->one();
  106. if (!$storeInfo) {
  107. continue;
  108. }
  109. if($storeInfo['category_id']>0){
  110. $categoryInfo = Cat::find()->where(['id'=>$storeInfo['category_id'],'is_delete'=>0])->asArray()->one();
  111. if($categoryInfo){
  112. $storeInfo['category_name'] = $categoryInfo['name'];
  113. }else{
  114. $storeInfo['category_name'] = '';
  115. }
  116. }
  117. $new_list[] = (object)[
  118. 'id' => $shop['id'],
  119. 'created_at' => $shop['created_at'],
  120. 'store_info' => $storeInfo
  121. //'goods_list' => Goods::find()->where(['store_id' => $this->store_id, 'status' => Goods::STATUS_NORMAL, 'is_delete' => 0, 'mch_id' => $shop['goods_id']])->select('id, price, cover_pic, mch_id')->limit(4)->orderBy('created_at DESC')->asArray()->all()
  122. ];
  123. }
  124. return [
  125. 'code' => 0,
  126. 'data' => (object)[
  127. 'row_count' => $count,
  128. 'page_count' => $pagination->pageCount,
  129. 'list' => $new_list,
  130. ],
  131. ];
  132. }
  133. }
  134. }