mshop.php 8.0 KB

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