config.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. use think\facade\Db;
  3. class Model20{
  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('pintuan_state', '=', \app\common\model\Ppintuan::PINTUAN_STATE_NORMAL);
  26. $condition[] = array('pintuan_end_time', '>', TIMESTAMP);
  27. $condition[] = array('pintuan_starttime', '<', TIMESTAMP);
  28. $subQuery=Db::name('ppintuan')->field('pintuan_goods_commonid')->where($condition)->buildSql();
  29. $ppintuan_model=model('ppintuan');
  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. $ppintuanInfo=$ppintuan_model->getPintuanInfoByGoodsCommonID($v1['goods_commonid']);
  42. if(!$ppintuanInfo){
  43. continue;
  44. }
  45. $v1['goods_image']=goods_thumb($v1);
  46. $v1['goods_promotion_price']=round($ppintuanInfo['pintuan_goods_price'] * $ppintuanInfo['pintuan_zhe'] / 10, 2);
  47. $v1['member_count']=$ppintuanInfo['pintuan_limit_number'];
  48. $v1['order_count']=$ppintuanInfo['pintuan_count'];
  49. if(empty($sorted_goods)){
  50. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  51. }else{
  52. $c=count($sorted_goods);
  53. foreach($sorted_goods as $k2 => $v2){
  54. if($v2['sort']>intval($config['goods_id'][$v1['goods_id']]['sort'])){
  55. array_splice($sorted_goods,$k2,0,array(array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])))));
  56. break;
  57. }
  58. }
  59. if($c==count($sorted_goods)){
  60. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  61. }
  62. }
  63. }
  64. $goods_list=$sorted_goods;
  65. }
  66. }else{
  67. $order='goods_id desc';
  68. switch(intval($config['goods_sort'])){
  69. case 2:
  70. $order='goods_salenum desc';
  71. break;
  72. case 3:
  73. $order='evaluation_good_star desc';
  74. break;
  75. }
  76. $where = array();
  77. if($store_id){
  78. $where[] = array('goodscommon.store_id','=',$store_id);
  79. }
  80. if ($config['goods_class']) {
  81. $where[]=array('goodscommon.gc_id_1|goodscommon.gc_id_2|goodscommon.gc_id_3|goodscommon.gc_id','=',intval($config['goods_class']));
  82. }
  83. $where[]=array('goodscommon.goods_commonid','exp',Db::raw('in '.$subQuery));
  84. //所需字段
  85. $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";
  86. $fieldstr .= ',goodscommon.is_virtual,goodscommon.is_goodsfcode,goods.is_have_gift,goodscommon.store_name,goodscommon.is_platform_store';
  87. $goods_list = $goods_model->getGoodsUnionList($where,$fieldstr , $order,'goodscommon.goods_commonid', intval($config['goods_count']));
  88. foreach($goods_list as $key => $val){
  89. $ppintuanInfo=$ppintuan_model->getPintuanInfoByGoodsCommonID($val['goods_commonid']);
  90. if(!$ppintuanInfo){
  91. unset($goods_list[$key]);
  92. }
  93. $goods_list[$key]['goods_image']=goods_thumb($val);
  94. $goods_list[$key]['goods_promotion_price']=round($ppintuanInfo['pintuan_goods_price'] * $ppintuanInfo['pintuan_zhe'] / 10, 2);
  95. $goods_list[$key]['member_count']=$ppintuanInfo['pintuan_limit_number'];
  96. $goods_list[$key]['order_count']=$ppintuanInfo['pintuan_count'];
  97. }
  98. $goods_list=array_values($goods_list);
  99. }
  100. $config['goods_list']=$goods_list;
  101. return ds_callback(true,'',$config);
  102. }
  103. }