config.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. class Model4{
  3. public function filterData($post){
  4. $data=array(
  5. 'back_color'=>$post['back_color'],
  6. 'padding_top'=>$post['padding_top'],
  7. 'padding_bottom'=>$post['padding_bottom'],
  8. 'if_fixed_goods'=>$post['if_fixed_goods'],
  9. 'goods_id'=>isset($post['goods_id'])?$post['goods_id']:array(),
  10. 'goods_count'=>$post['goods_count'],
  11. 'goods_class'=>$post['goods_class'],
  12. 'goods_sort'=>$post['goods_sort'],
  13. 'adv'=>$post['adv'],
  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. if($config['if_fixed_goods']==1){
  22. if(!empty($config['goods_id'])){
  23. $where=array();
  24. if($store_id){
  25. $where[] = array('store_id','=',$store_id);
  26. }
  27. $where[]=array('goods_id','in',array_keys($config['goods_id']));
  28. $goods_list=$goods_model->getGoodsOnlineList($where, '*', 0, 'goods_id desc');
  29. $sorted_goods=array();
  30. foreach($goods_list as $v1){
  31. if(empty($sorted_goods)){
  32. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  33. }else{
  34. $c=count($sorted_goods);
  35. foreach($sorted_goods as $k2 => $v2){
  36. if($v2['sort']>intval($config['goods_id'][$v1['goods_id']]['sort'])){
  37. array_splice($sorted_goods,$k2,0,array(array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])))));
  38. break;
  39. }
  40. }
  41. if($c==count($sorted_goods)){
  42. $sorted_goods[]=array_merge($v1,array('sort'=>intval($config['goods_id'][$v1['goods_id']]['sort'])));
  43. }
  44. }
  45. }
  46. $goods_list=$sorted_goods;
  47. }
  48. }else{
  49. $order='goods_id desc';
  50. switch(intval($config['goods_sort'])){
  51. case 2:
  52. $order='goods_salenum desc';
  53. break;
  54. case 3:
  55. $order='evaluation_good_star desc';
  56. break;
  57. }
  58. $where = array();
  59. if($store_id){
  60. $where[] = array('goodscommon.store_id','=',$store_id);
  61. }
  62. if ($config['goods_class']) {
  63. $where[]=array('goodscommon.gc_id_1|goodscommon.gc_id_2|goodscommon.gc_id_3|goodscommon.gc_id','=',intval($config['goods_class']));
  64. }
  65. //所需字段
  66. $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";
  67. $fieldstr .= ',goodscommon.is_virtual,goodscommon.is_goodsfcode,goods.is_have_gift,goodscommon.store_name,goodscommon.is_platform_store';
  68. $goods_list = $goods_model->getGoodsUnionList($where,$fieldstr , $order,'goodscommon.goods_commonid', intval($config['goods_count']));
  69. }
  70. $config['goods_list']=$goods_list;
  71. return ds_callback(true,'',$config);
  72. }
  73. }