activity.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/10/19
  6. * Time: 下午4:45
  7. */
  8. require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
  9. require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
  11. class act_formater
  12. {
  13. private $mActivities;
  14. private $mGoodsActContainer;
  15. public function __construct($activities)
  16. {
  17. $this->mActivities = $activities;
  18. $this->mGoodsActContainer = [];
  19. }
  20. public function format_acting(bonus\IPriceCalculate $price_calc)
  21. {
  22. $specials = [];
  23. $goods_ids = [];
  24. $cur_type = -1;
  25. foreach ($this->mActivities as $act)
  26. {
  27. $gids =[];
  28. $block = false;
  29. if(array_key_exists('xianshi_id',$act))
  30. {
  31. $block = $this->format_limit($act,$gids);
  32. if($block != false) {
  33. $time_type = intval($act['xianshi_type']);
  34. }
  35. }
  36. elseif(array_key_exists('groupbuy_id',$act))
  37. {
  38. $block = $this->format_groupbuy($act,$gids);
  39. if($block != false) {
  40. $time_type = intval($act['groupbuy_type']);
  41. }
  42. }
  43. else {
  44. $time_type = false;
  45. Log::record("an error activity.",Log::ERR);
  46. }
  47. if($block != false)
  48. {
  49. if($time_type !== false)
  50. {
  51. if($cur_type != $time_type)
  52. {
  53. $banners = $this->type_banner($time_type);
  54. if(!empty($banners))
  55. {
  56. foreach ($banners as $banner) {
  57. $specials[] = $banner;
  58. }
  59. }
  60. $cur_type = $time_type;
  61. }
  62. }
  63. $specials[]= $block;
  64. self::array_copy($goods_ids,$gids);
  65. }
  66. }
  67. $goods_ids = array_unique($goods_ids);
  68. if(!empty($goods_ids))
  69. {
  70. $helper = new goods_helper($price_calc);
  71. $ret = $helper->online_summary($goods_ids,$related);
  72. return array('special_list' => $specials,
  73. 'summary' => $ret['summary'],
  74. 'groupbuy' => $ret['groupbuy'],
  75. 'limitime' => $ret['limitime'],
  76. 'bundling' => $ret['bundling'],
  77. 'mobile_page' => mobile_page(1));
  78. }
  79. else {
  80. return array('special_list' => null,
  81. 'summary' => null,
  82. 'groupbuy' => null,
  83. 'limitime' => null,
  84. 'bundling' => null,
  85. 'mobile_page' => mobile_page(1));
  86. }
  87. }
  88. public function format_unstart(bonus\IPriceCalculate $price_calc)
  89. {
  90. $specials = [];
  91. $goods_ids = [];
  92. $group_ids = [];
  93. $limit_ids = [];
  94. $cur_type = -1;
  95. foreach ($this->mActivities as $act)
  96. {
  97. $gids = [];
  98. $block = false;
  99. if(array_key_exists('xianshi_id',$act))
  100. {
  101. $block = $this->format_limit($act,$gids);
  102. if($block != false) {
  103. $limit_ids[] = intval($act['xianshi_id']);
  104. $time_type = intval($act['xianshi_type']);
  105. }
  106. }
  107. elseif(array_key_exists('groupbuy_id',$act))
  108. {
  109. $block = $this->format_groupbuy($act,$gids);
  110. if($block != false) {
  111. $group_ids[] = intval($act['groupbuy_id']);
  112. $time_type = intval($act['groupbuy_type']);
  113. }
  114. }
  115. else {
  116. $time_type = false;
  117. Log::record("an error activity.",Log::ERR);
  118. }
  119. if($block != false)
  120. {
  121. if($time_type !== false)
  122. {
  123. if($cur_type != $time_type)
  124. {
  125. $banners = $this->type_banner($time_type);
  126. if(!empty($banners))
  127. {
  128. foreach ($banners as $banner) {
  129. $specials[] = $banner;
  130. }
  131. }
  132. $cur_type = $time_type;
  133. }
  134. }
  135. $specials[]= $block;
  136. self::array_copy($goods_ids,$gids);
  137. }
  138. }
  139. $goods_ids = array_unique($goods_ids);
  140. if(!empty($goods_ids))
  141. {
  142. $helper = new goods_helper($price_calc);
  143. $ret = $helper->online_summary($goods_ids,$related);
  144. $summarys = $ret['summary'];
  145. foreach ($summarys as &$summary)
  146. {
  147. $goods_id = $summary['goods_id'];
  148. $act = $this->mGoodsActContainer[$goods_id];
  149. $summary['act_id'] = $act['act_id'];
  150. $summary['act_type'] = $act['act_type'];
  151. if($act['act_type'] == activity_helper::ACTIVITY_GROUPBUY) {
  152. $ret = activity_helper::groupbuy_price($act['act_id'],$price);
  153. } else {
  154. $ret = activity_helper::limit_price($act['act_id'],$goods_id,$price);
  155. }
  156. if($ret == true) {
  157. $summary['goods_promotion_price'] = $price;
  158. } else {
  159. Log::record("can not get : goods_promotion_price",Log::ERR);
  160. }
  161. }
  162. $groups = [];
  163. foreach ($group_ids as $group_id)
  164. {
  165. $item = activity\groupbuy::instance()->get_info($group_id);
  166. if($item != false) {
  167. $groups[] = $item;
  168. } else {
  169. Log::record("cannot get group id={$group_id}",Log::ERR);
  170. }
  171. }
  172. $limits = [];
  173. foreach ($limit_ids as $limit_id)
  174. {
  175. $item = activity\limitime::instance()->get_info($limit_id);
  176. if($item != false) {
  177. $limits[] = $item;
  178. } else {
  179. Log::record("cannot get group id={$limit_id}",Log::ERR);
  180. }
  181. }
  182. return array('special_list' => $specials,
  183. 'summary' => $summarys,
  184. 'groupbuy' => $groups,
  185. 'limitime' => $limits,
  186. 'bundling' => $ret['bundling'],
  187. 'mobile_page' => mobile_page(1));
  188. }
  189. else
  190. {
  191. return array('special_list' => null,
  192. 'summary' => null,
  193. 'groupbuy' => null,
  194. 'limitime' => null,
  195. 'bundling' => null,
  196. 'mobile_page' => mobile_page(1));
  197. }
  198. }
  199. private function type_banner($time_type)
  200. {
  201. static $stTimeBanner = array(12 => 345,20 => 347,24 => 348);
  202. //static $stTimeBanner = array(12 => 60);
  203. if(array_key_exists($time_type,$stTimeBanner))
  204. {
  205. $banners = special_manager::instance()->special($stTimeBanner[$time_type],$gids);
  206. if(empty($banners))
  207. return null;
  208. else
  209. return $banners;
  210. }
  211. return null;
  212. }
  213. private function format_limit($limt, &$goods_ids)
  214. {
  215. $result =[];
  216. $limt_id = intval($limt['xianshi_id']);
  217. $result['item_title'] = strval($limt_id);
  218. $result['item_type'] = 'home_limit';
  219. $goods_ids = activity_helper::limit_goods($limt_id);
  220. if(empty($goods_ids)) return false;
  221. foreach ($goods_ids as $gid) {
  222. $item['type'] = 'goods';
  223. $item['data'] = strval($gid);
  224. $item['image'] = '';
  225. $item['title'] = '';
  226. $result['items'][] = $item;
  227. $this->mGoodsActContainer[$gid] = array('act_id' => $limt_id,
  228. 'act_type' => activity_helper::ACTIVITY_LIMITTIME);
  229. }
  230. return $result;
  231. }
  232. private function format_groupbuy($group, &$goods_ids)
  233. {
  234. $result =[];
  235. $act_id = intval($group['groupbuy_id']);
  236. $result['item_title'] = strval($act_id);
  237. $result['item_type'] = 'home_group';
  238. $goods_ids = activity_helper::groupbuy_goods($act_id);
  239. if(empty($goods_ids)) return false;
  240. foreach ($goods_ids as $gid) {
  241. $item['type'] = 'goods';
  242. $item['data'] = strval($gid);
  243. $item['image'] = '';
  244. $item['title'] = '';
  245. $result['items'][] = $item;
  246. $this->mGoodsActContainer[$gid] = array('act_id' => $act_id,
  247. 'act_type' => activity_helper::ACTIVITY_GROUPBUY,
  248. 'goods_promotion_price' => $group['promotion_price']);
  249. }
  250. return $result;
  251. }
  252. private static function array_copy(&$dest,$src)
  253. {
  254. if(empty($src)) return $dest;
  255. foreach ($src as $value) {
  256. array_push($dest,$value);
  257. }
  258. return $dest;
  259. }
  260. }
  261. class limit_outer
  262. {
  263. const WAIT_START = 0;
  264. const WAIT_END = 1;
  265. private $mAct;
  266. private $mType;
  267. public function __construct($type,$act)
  268. {
  269. $this->mAct = $act;
  270. $this->mType = $type;
  271. }
  272. public function format(bonus\IPriceCalculate $price_calc)
  273. {
  274. if(array_key_exists('xianshi_id',$this->mAct)) {
  275. $result = $this->format_limit($price_calc);
  276. }
  277. elseif(array_key_exists('groupbuy_id',$this->mAct)) {
  278. $result = $this->format_group($price_calc);
  279. }
  280. else {
  281. $result = false;
  282. }
  283. return $result;
  284. }
  285. private function format_limit(bonus\IPriceCalculate $price_calc)
  286. {
  287. $result = [];
  288. $act = $this->mAct;
  289. $act_id = $act['xianshi_id'];
  290. $gids = activity_helper::limit_goods($act_id);
  291. if(empty($gids)) return false;
  292. $goods_ids = array($gids[0]);
  293. $helper = new goods_helper($price_calc);
  294. $ret = $helper->online_summary($goods_ids,$related);
  295. if(!empty($ret['summary']))
  296. {
  297. $summary = $ret['summary'][0];
  298. if($this->mType == limit_outer::WAIT_START) {
  299. $result['act_time'] = $act['start_time'];
  300. } else {
  301. $result['act_time'] = $act['end_time'];
  302. }
  303. $result['goods_name'] = $summary['goods_mobile_name'];
  304. $result['goods_price'] = $summary['goods_price'];
  305. $result['goods_promotion_price'] = $summary['goods_promotion_price'];
  306. $result['goods_image_url'] = $summary['goods_image_url'];
  307. $result['local_time'] = time();
  308. return $result;
  309. }
  310. else {
  311. return false;
  312. }
  313. }
  314. private function format_group(bonus\IPriceCalculate $price_calc)
  315. {
  316. $result = [];
  317. $act = $this->mAct;
  318. $act_id = $act['groupbuy_id'];
  319. $gids = activity_helper::groupbuy_goods($act_id);
  320. if(empty($gids)) return false;
  321. $goods_ids = array($gids[0]);
  322. $helper = new goods_helper($price_calc);
  323. $ret = $helper->online_summary($goods_ids,$related);
  324. if(!empty($ret['summary']))
  325. {
  326. $summary = $ret['summary'][0];
  327. if($this->mType == limit_outer::WAIT_START) {
  328. $result['act_time'] = $act['start_time'];
  329. } else {
  330. $result['act_time'] = $act['end_time'];
  331. }
  332. $result['goods_name'] = $summary['goods_mobile_name'];
  333. $result['goods_price'] = $summary['goods_price'];
  334. $result['goods_promotion_price'] = $act['promotion_price'];
  335. $result['goods_image_url'] = $summary['goods_image_url'];
  336. $result['local_time'] = time();
  337. return $result;
  338. }
  339. else {
  340. return false;
  341. }
  342. }
  343. }
  344. class activityControl extends mobileControl
  345. {
  346. public function __construct()
  347. {
  348. parent::__construct();
  349. }
  350. public function actingOp()
  351. {
  352. $actings = activity_helper::acting();
  353. $formater = new act_formater($actings);
  354. $result = $formater->format_acting($this->price_calcer());
  355. return self::outsuccess($result);
  356. }
  357. public function unstartOp()
  358. {
  359. $actings = activity_helper::unstart();
  360. $formater = new act_formater($actings);
  361. $result = $formater->format_unstart($this->price_calcer());
  362. return self::outsuccess($result);
  363. }
  364. public function limit_entraOp()
  365. {
  366. $_SESSION['client_type'] = "wap";
  367. $acts = activity_helper::acting();
  368. $price_calcer = $this->price_calcer();
  369. if(!empty($acts)) {
  370. $act = $acts[0];
  371. $outer = new limit_outer(limit_outer::WAIT_END,$act);
  372. $result = $outer->format($price_calcer);
  373. if($result != false) {
  374. return self::outsuccess($result,"activity/limit_entra");
  375. }
  376. }
  377. $unstarts = activity_helper::unstart();
  378. if(!empty($unstarts)) {
  379. $act = $unstarts[0];
  380. $outer = new limit_outer(limit_outer::WAIT_START,$act);
  381. $result = $outer->format($price_calcer);
  382. if($result != false) {
  383. return self::outsuccess($result,"activity/limit_entra");
  384. }
  385. }
  386. return self::outsuccess(null,"activity/limit_entra");
  387. }
  388. }