goods_common.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/8/25
  6. * Time: 下午4:18
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/brand_helper.php');
  9. require_once(BASE_ROOT_PATH . '/helper/user_session/fcode.php');
  10. abstract class common_base
  11. {
  12. protected $commonid;
  13. protected $common_info;
  14. protected $store_id;
  15. public function __construct($param)
  16. {
  17. if (is_array($param)) {
  18. $this->common_info = $param;
  19. $this->commonid = intval($this->common_info['goods_commonid']);
  20. $this->store_id = intval($this->common_info['store_id']);
  21. }
  22. }
  23. public abstract function format();
  24. }
  25. class common_sumary extends common_base
  26. {
  27. public function __construct($param)
  28. {
  29. parent::__construct($param);
  30. }
  31. public function format()
  32. {
  33. $ret['goods_commonid'] = intval($this->common_info['goods_commonid']);
  34. $ret['goods_commend'] = intval($this->common_info['goods_commend']);
  35. $ret['comments'] = intval($this->common_info['comments']);
  36. $brand_id = intval($this->common_info['brand_id']);
  37. $ret['brand_id'] = $brand_id;
  38. $ret['brand_name'] = brand_helper::instance()->name($brand_id);
  39. $ret['type_id'] = intval($this->common_info['type_id']);
  40. $ret['gc_id'] = intval($this->common_info['gc_id_3']);
  41. $ret['goods_selltime'] = intval($this->common_info['goods_selltime']);
  42. $ret['goods_freight'] = doubleval($this->common_info['goods_freight']);
  43. $is_fcode = intval($this->common_info['is_fcode']) == 1 ? true : false;
  44. $ret['is_fcode'] = $is_fcode;
  45. if($is_fcode) {
  46. $fcode = new user_session\fcode();
  47. $ret['has_fcode'] = $fcode->usable_num($this->commonid,$lock_num) == false ? false : true;
  48. } else {
  49. $ret['has_fcode'] = false;
  50. }
  51. if($ret['has_fcode']) {
  52. $ret['fcode_desc'] = "你有F码,可以购买";
  53. }
  54. else
  55. {
  56. if(isset($lock_num) && $lock_num > 0) {
  57. $ret['fcode_desc'] = "F码处于锁定状态,激活后可以购买";
  58. } else {
  59. $ret['fcode_desc'] = "你没有该商品的F码";
  60. }
  61. }
  62. return $ret;
  63. }
  64. }
  65. class common_spec extends common_base
  66. {
  67. private $have_spec;
  68. private $spec_name;
  69. private $spec_list;
  70. private $attr_list;
  71. public function __construct($param,$goods_list)
  72. {
  73. parent::__construct($param);
  74. $spec_name = unserialize($this->common_info['spec_name']);
  75. if(empty($spec_name)) {
  76. $this->have_spec = false;
  77. $this->spec_name = '';
  78. }
  79. else
  80. {
  81. $this->have_spec = true;
  82. foreach ($spec_name as $spid => $spname) {
  83. $this->spec_name = $spname;
  84. break;
  85. }
  86. }
  87. $spec_value = unserialize($this->common_info['spec_value']);
  88. if(!empty($spec_value))
  89. {
  90. foreach ($spec_value as $sp_id => $sp_val)
  91. {
  92. foreach ($sp_val as $spv_id => $spv_name) {
  93. $this->spec_list[$spv_id]['spv_name'] = $spv_name;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. $this->spec_list = array();
  100. }
  101. foreach ($goods_list as $value)
  102. {
  103. $goods_id = intval($value['goods_id']);
  104. $spec = unserialize($value['goods_spec']);
  105. if(!empty($spec))
  106. {
  107. foreach ($spec as $spv_id => $spv_name) {
  108. $this->spec_list[$spv_id]['goods_id'] = $goods_id;
  109. }
  110. }
  111. }
  112. $attrs = unserialize($this->common_info['goods_attr']);
  113. $this->attr_list = [];
  114. if(!empty($attrs))
  115. {
  116. foreach ($attrs as $key => $val)
  117. {
  118. foreach ($val as $attr_key => $attr_val)
  119. {
  120. if($attr_key === 'name') {
  121. $name = $attr_val;
  122. } else {
  123. $value = $attr_val;
  124. }
  125. }
  126. $this->attr_list[] = ["name" => $name,"value" => $value];
  127. }
  128. }
  129. }
  130. public function format()
  131. {
  132. $ret['have_spec'] = $this->have_spec;
  133. $ret['spec_name'] = $this->spec_name;
  134. $ret['skus'] = array();
  135. foreach ($this->spec_list as $key => $value) {
  136. array_push($ret['skus'],$value);
  137. }
  138. $ret['attrs'] = $this->attr_list;
  139. return $ret;
  140. }
  141. }
  142. class goods_common extends common_base
  143. {
  144. private $goods_list;
  145. private $goods_ids;
  146. private $show_gid;
  147. public function __construct($common_info,$goods_list,$show_gid)
  148. {
  149. parent::__construct($common_info);
  150. $this->goods_list = $goods_list;
  151. $this->goods_ids = $this->goods_ids();
  152. $show_gid = intval($show_gid);
  153. if(in_array($show_gid,$this->goods_ids)) {
  154. $this->show_gid = $show_gid;
  155. } else {
  156. $this->show_gid = $this->goods_ids[0];
  157. }
  158. }
  159. public function goods_ids()
  160. {
  161. $ids = array();
  162. foreach ($this->goods_list as $value) {
  163. $gid = intval($value['goods_id']);
  164. array_push($ids,$gid);
  165. }
  166. return $ids;
  167. }
  168. static private function img_url($value,$store_id)
  169. {
  170. return cthumb($value, 1280, $store_id);
  171. }
  172. private function goods_images()
  173. {
  174. $mod = Model('goods');
  175. $items = $mod->getGoodsImageListEx(array('goods_commonid' => $this->commonid));
  176. $images = array();
  177. foreach ($items as $val) {
  178. $img = $val['goods_image'];
  179. $images[] = self::img_url($img,$this->store_id);
  180. }
  181. return $images;
  182. }
  183. public function format()
  184. {
  185. $summary = new common_sumary($this->common_info);
  186. $base_info = $summary->format();
  187. $goods_spec = new common_spec($this->common_info,$this->goods_list);
  188. $spec = $goods_spec->format();
  189. $ret = array_merge($base_info,$spec);
  190. $ret['images'] = $this->goods_images();
  191. $ret['show_goods'] = $this->show_gid;
  192. //todo use true data
  193. $ret['comments_rate'] = (float)4.5;
  194. $ret['brand_tip'] = "正品保障 | 品牌授权 | 7天无忧退货";
  195. $ret['brand_desc_url'] = RESOURCE_SITE_URL . '/mobile/defimg/brand_detail_desc.png';
  196. $ret['brand_desc_width'] = 1080;
  197. $ret['brand_desc_height'] = 1080;
  198. $ret['room_id'] = 37;
  199. $ret['room_name'] = "打假房间";
  200. return $ret;
  201. }
  202. }