mshop.php 7.4 KB

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