Group.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 团购管理
  7. */
  8. namespace app\fastshop\model;
  9. use think\Model;
  10. use filter\Filter;
  11. class Group extends Model{
  12. protected $pk = 'id';
  13. protected $table = 'ai_fastshop_group';
  14. public function item(){
  15. return $this->hasOne('Item','id','item_id');
  16. }
  17. /**
  18. * 读取商品列表
  19. * @param string $status
  20. * @param string $keyword
  21. * @return void
  22. */
  23. public function lists(int $member_id){
  24. return self::where(['member_miniapp_id' => $member_id])->order('id desc')->paginate(10);
  25. }
  26. /**
  27. * 读取需要选择商品列表
  28. *
  29. * @param integer $sid 专题ID
  30. * @param integer $cid 栏目ID
  31. * @param string $keyword 搜索关键字
  32. * @return void
  33. */
  34. public function itemList(int $member_id,int $cid,string $keyword = null){
  35. $where = [];
  36. $where[] = ['member_miniapp_id','=',$member_id];
  37. $where[] = ['is_sale','<>',1];
  38. if ($cid) {
  39. $where[] = ['','exp', self::raw("FIND_IN_SET({$cid},category_path_id)")];
  40. }
  41. if(!empty($keyword)){
  42. $keyword = Filter::filter_escape($keyword);
  43. $where[] = ["name","like","%{$keyword}%"];
  44. }
  45. return model('Item')->alias('A')->where($where)->whereNotExists(function ($query){
  46. $query->table('ai_fastshop_group')->alias('B')->WHERE("A.id","=","B.item_id");
  47. })->order('sort desc,id desc')->paginate(20,false,['query'=>['cid' => $cid,'keyword' => $keyword]]);
  48. }
  49. /**
  50. * 批量选择操作
  51. * @param int $sid 专题ID
  52. * @param string $ids 要批量操作的ids
  53. */
  54. public function ids_action(int $member_miniapp_id,string $ids){
  55. $ids = ids($ids,true);
  56. $data = [];
  57. foreach ($ids as $key => $id) {
  58. $data[$key]['member_miniapp_id'] = $member_miniapp_id;
  59. $data[$key]['item_id'] = $id;
  60. $data[$key]['amount'] = 0;
  61. $data[$key]['hao_people'] = 10;
  62. $data[$key]['uids'] = json_encode([]);
  63. }
  64. if(!empty($data)){
  65. return self::insertAll($data);
  66. }
  67. return false;
  68. }
  69. }