mshop.php 8.0 KB

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