config.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. use think\facade\Db;
  3. class Model18{
  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('bargain_state','=',\app\common\model\Pbargain::PINTUAN_STATE_NORMAL);
  26. $condition[] = array('bargain_endtime','>',TIMESTAMP);
  27. $condition[] = array('bargain_begintime','<',TIMESTAMP);
  28. $subQuery=Db::name('pbargain')->field('bargain_goods_id')->where($condition)->buildSql();
  29. $pbargain_model=model('pbargain');
  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_id','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. $bargainInfo=$pbargain_model->getBargainInfoByGoodsID($v1['goods_id']);
  42. if(!$bargainInfo){
  43. continue;
  44. }
  45. $v1['goods_image']=goods_thumb($v1);
  46. $v1['goods_promotion_price']=$bargainInfo['bargain_floorprice'];
  47. $v1['order_count']=Db::name('ordergoods')->where(array(array('goods_type','=',8),array('goods_id','=',$v1['goods_id'])))->sum('goods_num');
  48. if(empty($sorted_goods)){
  49. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  50. }else{
  51. $c=count($sorted_goods);
  52. foreach($sorted_goods as $k2 => $v2){
  53. if($v2['sort']>intval($config['goods_id'][$v1['goods_id']]['sort'])){
  54. array_splice($sorted_goods,$k2,0,array(array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])))));
  55. break;
  56. }
  57. }
  58. if($c==count($sorted_goods)){
  59. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  60. }
  61. }
  62. }
  63. $goods_list=$sorted_goods;
  64. }
  65. }else{
  66. $order='goods_id desc';
  67. switch(intval($config['goods_sort'])){
  68. case 2:
  69. $order='goods_salenum desc';
  70. break;
  71. case 3:
  72. $order='evaluation_good_star desc';
  73. break;
  74. }
  75. $where = array();
  76. if($store_id){
  77. $where[] = array('goodscommon.store_id','=',$store_id);
  78. }
  79. if ($config['goods_class']) {
  80. $where[]=array('goodscommon.gc_id_1|goodscommon.gc_id_2|goodscommon.gc_id_3|goodscommon.gc_id','=',intval($config['goods_class']));
  81. }
  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. $where[]=array('goods_id','exp',Db::raw('in '.$subQuery));
  86. $goods_list = $goods_model->getGoodsUnionList($where,$fieldstr , $order,'goodscommon.goods_commonid', intval($config['goods_count']));
  87. foreach($goods_list as $key => $val){
  88. $bargainInfo=$pbargain_model->getBargainInfoByGoodsID($val['goods_id']);
  89. if(!$bargainInfo){
  90. unset($goods_list[$key]);
  91. }
  92. $goods_list[$key]['goods_image']=goods_thumb($val);
  93. $goods_list[$key]['goods_promotion_price']=$bargainInfo['bargain_floorprice'];
  94. $goods_list[$key]['order_count']=Db::name('ordergoods')->where(array(array('goods_type','=',8),array('goods_id','=',$val['goods_id'])))->sum('goods_num');
  95. }
  96. $goods_list=array_values($goods_list);
  97. }
  98. $config['goods_list']=$goods_list;
  99. return ds_callback(true,'',$config);
  100. }
  101. }