mshop.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/6/13
  6. * Time: 下午3:51
  7. */
  8. defined('InShopNC') or exit('Access Invalid!');
  9. require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/index_tab.php');
  12. require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
  13. require_once(BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
  14. require_once(BASE_ROOT_PATH . '/mobile/control/special.php');
  15. require_once(BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
  16. require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
  17. require_once(BASE_ROOT_PATH . '/helper/third_author/signaturer.php');
  18. require_once(BASE_ROOT_PATH . '/helper/predeposit_helper.php');
  19. require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
  20. class mshopControl extends specialControl
  21. {
  22. public function __construct() {
  23. parent::__construct();
  24. }
  25. public function indexOp()
  26. {
  27. $this->topup();
  28. $url = BASE_SITE_URL . "/mshop/";
  29. if(session_helper::need_wechat_author())
  30. {
  31. $author = new thrid_author\wxauthor();
  32. $url = $author->enter($url);
  33. }
  34. return self::outsuccess(['direct_uri' => $url],"redirect");
  35. }
  36. public function authorOp()
  37. {
  38. $url = $_GET['url'];
  39. $msg = "跳转的地址不能为空.";
  40. if(empty($url)) {
  41. return self::outerr(errcode::ErrParamter,$msg);
  42. }
  43. $url = urldecode($url);
  44. if(empty($url)) {
  45. return self::outerr(errcode::ErrParamter,$msg);
  46. }
  47. if(session_helper::need_wechat_author())
  48. {
  49. $author = new thrid_author\wxauthor();
  50. $url = $author->enter($url);
  51. return self::outsuccess(['direct_uri' => $url],"redirect");
  52. }
  53. else {
  54. return self::outsuccess(['direct_uri' => $url],"redirect");
  55. }
  56. }
  57. public function tabsOp()
  58. {
  59. return self::outsuccess(['tabs' => [['special_id' => 0,'name' => "首页"]]]);
  60. }
  61. public function goodsOp()
  62. {
  63. $this->topup();
  64. $goods_id = intval($_GET['goods_id']);
  65. if($goods_id <= 0) {
  66. $url = BASE_SITE_URL . "/mshop";
  67. }
  68. else {
  69. $url = BASE_SITE_URL . "/mshop/goods_detail?goods_id={$goods_id}";
  70. }
  71. $relay_id = session_helper::relay_id();
  72. fcgi_setcookie("relay_id","{$relay_id}",time() + 86400,'/',LOCAL_DOMAIN);
  73. if(session_helper::need_wechat_author())
  74. {
  75. $author = new thrid_author\wxauthor();
  76. $url = $author->enter($url);
  77. return self::outsuccess(['direct_uri' => $url],"redirect");
  78. }
  79. else {
  80. return self::outsuccess(['direct_uri' => $url],"redirect");
  81. }
  82. }
  83. public function specialOp()
  84. {
  85. $this->topup();
  86. $special_id = intval($_GET['special_id']);
  87. $title = $_GET['title'];
  88. if($special_id <= 0) {
  89. $url = BASE_SITE_URL . "/mshop";
  90. }
  91. else
  92. {
  93. if(empty($title)) {
  94. $title = $this->special_name($special_id);
  95. $title = util::base64url_encode($title);
  96. }
  97. $url = BASE_SITE_URL . "/mshop/special?special_id={$special_id}&is_special=true&title={$title}";
  98. }
  99. $relay_id = session_helper::relay_id();
  100. fcgi_setcookie("relay_id","{$relay_id}",time() + 86400,'/',LOCAL_DOMAIN);
  101. if(session_helper::need_wechat_author())
  102. {
  103. $author = new thrid_author\wxauthor();
  104. $url = $author->enter($url);
  105. return self::outsuccess(['direct_uri' => $url],"redirect");
  106. }
  107. else {
  108. return self::outsuccess(['direct_uri' => $url],"redirect");
  109. }
  110. }
  111. private function special_name($special_id)
  112. {
  113. $mod = Model('mb_special');
  114. $special = $mod->getMbSpecialList(['special_id' => $special_id]);
  115. if(empty($special)) return false;
  116. return $special[0]['special_desc'];
  117. }
  118. private function special_shareimg($special_id)
  119. {
  120. $defimg = RESOURCE_SITE_URL . "/mobile/defimg/panda.jpeg";
  121. $mod = Model('mb_special');
  122. $special = $mod->getMbSpecialList(['special_id' => $special_id]);
  123. if(empty($special)) return $defimg;
  124. $share_img = $special[0]['share_image'];
  125. if(empty($share_img)) {
  126. return $defimg;
  127. } else {
  128. return $share_img;
  129. }
  130. }
  131. public function signurlOp()
  132. {
  133. $sign_url = urldecode($_GET['sign_url']);
  134. if(empty($sign_url)) {
  135. return self::outerr(errcode::ErrParamter);
  136. }
  137. Log::record("signurl={$sign_url}",Log::DEBUG);
  138. $result = thrid_author\signaturer::instance()->signurl($sign_url);
  139. if($result == false) {
  140. return self::outerr(errcode::ErrAuthor);
  141. } else {
  142. return self::outsuccess($result);
  143. }
  144. }
  145. public function testOp()
  146. {
  147. return self::outsuccess("",'signature');
  148. }
  149. public function shareOp()
  150. {
  151. $type = $_GET['type'];
  152. $valid = intval($_GET['data']);
  153. if(empty($type) || $valid <= 0) {
  154. return self::outerr(errcode::ErrParamter);
  155. }
  156. $success = false;
  157. if($type == 'special')
  158. {
  159. $url = url_helper::mshop_special($valid);
  160. $title = $this->special_name($valid);
  161. if($title != false) {
  162. $success = true;
  163. $sub_title = "丽人丽妆 内买商城\n\n点击浏览";
  164. $img_url = $this->special_shareimg($valid);
  165. }
  166. }
  167. elseif($type == 'goods')
  168. {
  169. $url = url_helper::mshop_goods($valid);
  170. $goods_info = $this->goods_share($valid);
  171. if ($goods_info != false)
  172. {
  173. $success = true;
  174. $name = $goods_info['goods_mobile_name'];
  175. if (session_helper::logined()) {
  176. $nick_name = session_helper::nickname();
  177. $title = "{$nick_name}向您推荐 {$name}";
  178. } else {
  179. $title = "熊猫美妆向您推荐{$name}";;
  180. }
  181. $tip = $goods_info['goods_jingle'];
  182. if(empty($title)) {
  183. $sub_title = "丽人丽妆 内买商城\n\n点击浏览";
  184. } else {
  185. $sub_title = "{$tip}\n\n点击浏览";
  186. }
  187. $img_url = $this->img_url($goods_info['goods_image'],$goods_info['store_id']);
  188. }
  189. }
  190. if($success == false) {
  191. return self::outerr(errcode::ErrParamter);
  192. } else {
  193. return self::outsuccess(['url' => $url,'title' => $title,'sub_title' => $sub_title,'img_url' => $img_url]);
  194. }
  195. }
  196. private function goods_share($goods_id)
  197. {
  198. $mod_goods = Model('goods');
  199. $info = $mod_goods->getGoodsInfoByID($goods_id);
  200. if(empty($info)) {
  201. return false;
  202. } else {
  203. return $info;
  204. }
  205. }
  206. private function img_url($value,$store_id)
  207. {
  208. return cthumb($value, 240, $store_id);
  209. }
  210. private function topup()
  211. {
  212. if(session_helper::logined()) {
  213. $pred = new predeposit_helper($_SESSION['member_id'],true);
  214. $pred->topup_bonus($_SESSION['member_mobile']);
  215. }
  216. }
  217. }