config.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. use think\facade\Db;
  3. class Model19{
  4. public function filterData($post){
  5. $data=array(
  6. 'back_color'=>$post['back_color'],
  7. 'goods_count'=>$post['goods_count'],
  8. 'goods_class'=>$post['goods_class'],
  9. 'goods_sort'=>$post['goods_sort'],
  10. 'if_show_title_icon'=>$post['if_show_title_icon'],
  11. 'title_icon'=>$post['title_icon'],
  12. 'if_fixed_goods'=>$post['if_fixed_goods'],
  13. 'goods_id'=>isset($post['goods_id'])?$post['goods_id']:array(),
  14. );
  15. return ds_callback(true,'',$data);
  16. }
  17. public function formatData($config,$store_id=0){
  18. $config=json_decode($config,true);
  19. $goods_model=model('goods');
  20. $goods_list=array();
  21. $condition=array();
  22. if($store_id){
  23. $condition[] = array('store_id','=',$store_id);
  24. }
  25. $condition[] = array('groupbuy_state','=',\app\common\model\Groupbuy::GROUPBUY_STATE_NORMAL);
  26. $condition[] = array('groupbuy_endtime','>',TIMESTAMP);
  27. $condition[] = array('groupbuy_starttime','<',TIMESTAMP);
  28. $subQuery=Db::name('groupbuy')->field('goods_commonid')->where($condition)->buildSql();
  29. $groupbuy_model=model('groupbuy');
  30. if($config['if_fixed_goods']==1){
  31. if(!empty($config['goods_id'])){
  32. $where=array();
  33. if($store_id){
  34. $where[] = array('store_id','=',$store_id);
  35. }
  36. $where[]=array('goods_id','in',array_keys($config['goods_id']));
  37. $where[]=array('goods_commonid','exp',Db::raw('in '.$subQuery));
  38. $goods_list=$goods_model->getGoodsOnlineList($where, '*', 0, 'goods_id desc');
  39. $sorted_goods=array();
  40. foreach($goods_list as $v1){
  41. $groupbuyInfo=$groupbuy_model->getGroupbuyInfoByGoodsCommonID($v1['goods_commonid']);
  42. if(!$groupbuyInfo){
  43. continue;
  44. }
  45. $v1['goods_image']=goods_thumb($v1);
  46. $v1['order_count']=$groupbuyInfo['groupbuy_buyer_count'];
  47. if(empty($sorted_goods)){
  48. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  49. }else{
  50. $c=count($sorted_goods);
  51. foreach($sorted_goods as $k2 => $v2){
  52. if($v2['sort']>intval($config['goods_id'][$v1['goods_id']]['sort'])){
  53. array_splice($sorted_goods,$k2,0,array(array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])))));
  54. break;
  55. }
  56. }
  57. if($c==count($sorted_goods)){
  58. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  59. }
  60. }
  61. }
  62. $goods_list=$sorted_goods;
  63. }
  64. }else{
  65. $order='goods_id desc';
  66. switch(intval($config['goods_sort'])){
  67. case 2:
  68. $order='goods_salenum desc';
  69. break;
  70. case 3:
  71. $order='evaluation_good_star desc';
  72. break;
  73. }
  74. $where = array();
  75. if($store_id){
  76. $where[] = array('goodscommon.store_id','=',$store_id);
  77. }
  78. if ($config['goods_class']) {
  79. $where[]=array('goodscommon.gc_id_1|goodscommon.gc_id_2|goodscommon.gc_id_3|goodscommon.gc_id','=',intval($config['goods_class']));
  80. }
  81. $where[]=array('goodscommon.goods_commonid','exp',Db::raw('in '.$subQuery));
  82. //所需字段
  83. $fieldstr = "goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.store_id,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_price,goods.goods_promotion_price,goods.goods_promotion_type,goodscommon.goods_marketprice,goodscommon.goods_image,goods.goods_salenum,goods.evaluation_good_star,goods.evaluation_count";
  84. $fieldstr .= ',goodscommon.is_virtual,goodscommon.is_goodsfcode,goods.is_have_gift,goodscommon.store_name,goodscommon.is_platform_store';
  85. $goods_list = $goods_model->getGoodsUnionList($where,$fieldstr , $order,'goodscommon.goods_commonid', intval($config['goods_count']));
  86. foreach($goods_list as $key => $val){
  87. $groupbuyInfo=$groupbuy_model->getGroupbuyInfoByGoodsCommonID($val['goods_commonid']);
  88. if(!$groupbuyInfo){
  89. unset($goods_list[$key]);
  90. }
  91. $goods_list[$key]['goods_image']=goods_thumb($val);
  92. $goods_list[$key]['order_count']=$groupbuyInfo['groupbuy_buyer_count'];
  93. }
  94. $goods_list=array_values($goods_list);
  95. }
  96. $config['goods_list']=$goods_list;
  97. return ds_callback(true,'',$config);
  98. }
  99. }