Pointprod.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 积分兑换控制器
  10. */
  11. class Pointprod extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/pointprod.lang.php');
  17. //判断系统是否开启积分兑换功能
  18. if (config('ds_config.points_isuse') != 1 || config('ds_config.pointprod_isuse') != 1) {
  19. ds_json_encode(10001, lang('pointshop_unavailable'));
  20. }
  21. }
  22. public function index()
  23. {
  24. $this->plist();
  25. }
  26. /**
  27. * @api {POST} api/Pointprod/plist 积分商品列表
  28. * @apiVersion 1.0.0
  29. * @apiGroup Pointprod
  30. *
  31. * @apiHeader {String} X-DS-KEY 用户授权token
  32. *
  33. * @apiParam {String} level 会员级别
  34. * @apiParam {String} isable 仅我能兑换 0否 1是
  35. * @apiParam {String} points_min 积分从
  36. * @apiParam {String} points_max 积分到
  37. * @apiParam {String} orderby 排序 stimedesc积分兑换开始时间降序 stimeasc积分兑换开始时间升序 pointsdesc兑换积分降序 pointsasc兑换积分升序
  38. * @apiParam {String} page 页码
  39. * @apiParam {String} per_page 每页数量
  40. *
  41. * @apiSuccess {String} code 返回码,10000为成功
  42. * @apiSuccess {String} message 返回消息
  43. * @apiSuccess {Object} result 返回数据
  44. * @apiSuccess {Object[]} result.goods_list 积分商品列表 (返回字段参考pointsgoods表)
  45. * @apiSuccess {String} result.goods_list.ex_state 兑换状态代码 end不可兑换willbe即将开始going进行中
  46. * @apiSuccess {Int} result.goods_list.pgoods_limitgradename 所需用户等级
  47. * @apiSuccess {Object} result.grade_list 返回数据,键为等级ID
  48. * @apiSuccess {Int} result.grade_list.exppoints 所需积分
  49. * @apiSuccess {Int} result.grade_list.level 等级ID
  50. * @apiSuccess {String} result.grade_list.level_name 等级名称
  51. * @apiSuccess {String} result.ww json化的查询条件
  52. * @apiSuccess {Int} result.page_total 总页数
  53. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  54. */
  55. public function plist()
  56. {
  57. $pointprod_model = model('pointprod');
  58. //展示状态
  59. $pgoodsshowstate_arr = $pointprod_model->getPgoodsShowState();
  60. //开启状态
  61. $pgoodsopenstate_arr = $pointprod_model->getPgoodsOpenState();
  62. $member_model = model('member');
  63. //查询会员等级
  64. $membergrade_arr = $member_model->getMemberGradeArr();
  65. //查询兑换服务列表
  66. $where = array();
  67. $where[] = array('pgoods_show', '=', $pgoodsshowstate_arr['show'][0]);
  68. $where[] = array('pgoods_state', '=', $pgoodsopenstate_arr['open'][0]);
  69. //会员级别
  70. $level_filter = array();
  71. if (input('level')) {
  72. $level_filter['search'] = intval(input('level'));
  73. }
  74. if (input('isable') == 1) {
  75. if ($memberid = $this->getMemberIdIfExists()) {
  76. $member_infotmp = model('member')->getMemberInfoByID($memberid);
  77. //当前登录会员等级信息
  78. $membergrade_info = $member_model->getOneMemberGrade($member_infotmp['member_exppoints'], true);
  79. $this->member_info = array_merge($member_infotmp, $membergrade_info);
  80. }
  81. }
  82. if (input('isable') == 1 && isset($this->member_info['level'])) {
  83. $level_filter['isable'] = intval($this->member_info['level']);
  84. }
  85. if (count($level_filter) > 0) {
  86. if (isset($level_filter['search']) && isset($level_filter['isable'])) {
  87. $where[] = array('pgoods_limitmgrade', '=', $level_filter['search']);
  88. $where[] = array('pgoods_limitmgrade', '<=', $level_filter['isable']);
  89. } elseif (isset($level_filter['search'])) {
  90. $where[] = array('pgoods_limitmgrade', '=', $level_filter['search']);
  91. } elseif (isset($level_filter['isable'])) {
  92. $where[] = array('pgoods_limitmgrade', '<=', $level_filter['isable']);
  93. }
  94. }
  95. //查询仅我能兑换和所需积分
  96. $points_filter = array();
  97. if (input('isable') == 1 && isset($this->member_info['level'])) {
  98. $points_filter['isable'] = $this->member_info['member_points'];
  99. }
  100. if (input('points_min') > 0) {
  101. $points_filter['min'] = intval(input('points_min'));
  102. }
  103. if (input('points_max') > 0) {
  104. $points_filter['max'] = intval(input('points_max'));
  105. }
  106. if (count($points_filter) > 0) {
  107. asort($points_filter);
  108. if (count($points_filter) > 1) {
  109. $points_filter = array_values($points_filter);
  110. $where[] = array('pgoods_points', 'between', array($points_filter[0], $points_filter[1]));
  111. } else {
  112. if ($points_filter['min']) {
  113. $where[] = array('pgoods_points', '>=', $points_filter['min']);
  114. } elseif ($points_filter['max']) {
  115. $where[] = array('pgoods_points', '<=', $points_filter['max']);
  116. } elseif ($points_filter['isable']) {
  117. $where[] = array('pgoods_points', '<=', $points_filter['isable']);
  118. }
  119. }
  120. }
  121. //排序
  122. switch (input('orderby')) {
  123. case 'stimedesc':
  124. $orderby = 'pgoods_starttime desc,';
  125. break;
  126. case 'stimeasc':
  127. $orderby = 'pgoods_starttime asc,';
  128. break;
  129. case 'pointsdesc':
  130. $orderby = 'pgoods_points desc,';
  131. break;
  132. case 'pointsasc':
  133. $orderby = 'pgoods_points asc,';
  134. break;
  135. default:
  136. $orderby = '';
  137. }
  138. $orderby .= 'pgoods_sort asc,pgoods_id desc';
  139. $pageSize = 10;
  140. $pointprod_list = $pointprod_model->getPointProdList($where, "*", $orderby, '', $pageSize);
  141. $page_count = $pointprod_model->page_info;
  142. $result = array_merge(array('goods_list' => $pointprod_list, 'grade_list' => $membergrade_arr, 'ww' => json_encode($where)), mobile_page($page_count));
  143. ds_json_encode(10000, '', $result);
  144. }
  145. /**
  146. * @api {POST} api/Pointprod/pinfo 积分商品详情
  147. * @apiVersion 1.0.0
  148. * @apiGroup Pointprod
  149. *
  150. * @apiHeader {String} X-DS-KEY 用户授权token
  151. *
  152. * @apiParam {String} id 积分商品id
  153. *
  154. * @apiSuccess {String} code 返回码,10000为成功
  155. * @apiSuccess {String} message 返回消息
  156. * @apiSuccess {Object} result 返回数据
  157. * @apiSuccess {Object[]} result.goods_commend_list 推荐积分商品列表 (返回字段参考pointsgoods表)
  158. * @apiSuccess {String} result.goods_commend_list.ex_state 兑换状态代码 end不可兑换willbe即将开始going进行中
  159. * @apiSuccess {Int} result.goods_commend_list.pgoods_limitgradename 所需用户等级
  160. * @apiSuccess {Object} result.goods_info 积分商品信息 (返回字段参考pointsgoods表)
  161. * @apiSuccess {String} result.goods_info.ex_state 兑换状态代码 end不可兑换willbe即将开始going进行中
  162. * @apiSuccess {Int} result.goods_info.pgoods_limitgradename 所需用户等级
  163. */
  164. public function pinfo()
  165. {
  166. $pid = intval(input('id'));
  167. if (!$pid) {
  168. ds_json_encode(10001, lang('param_error'));
  169. }
  170. $pointprod_model = model('pointprod');
  171. //查询兑换礼品详细
  172. $prodinfo = $pointprod_model->getOnlinePointProdInfo(array(array('pgoods_id', '=', $pid)));
  173. if (empty($prodinfo)) {
  174. ds_json_encode(10001, lang('pointprod_goodsrecord_error'));
  175. }
  176. //更新礼品浏览次数
  177. $tm_tm_visite_pgoods = cookie('tm_visite_pgoods');
  178. $tm_tm_visite_pgoods = $tm_tm_visite_pgoods ? explode(',', $tm_tm_visite_pgoods) : array();
  179. if (!in_array($pid, $tm_tm_visite_pgoods)) { //如果已经浏览过该服务则不重复累计浏览次数
  180. $result = $pointprod_model->editPointProdViewnum($pid);
  181. if ($result['state'] == true) { //累加成功则cookie中增加该服务ID
  182. $tm_tm_visite_pgoods[] = $pid;
  183. cookie('tm_visite_pgoods', implode(',', $tm_tm_visite_pgoods));
  184. }
  185. }
  186. //热门积分兑换服务
  187. $recommend_pointsprod = $pointprod_model->getRecommendPointProd(5);
  188. $prodinfo['pgoods_body'] = htmlspecialchars_decode($prodinfo['pgoods_body']);
  189. ds_json_encode(10000, '', array('goods_commend_list' => $recommend_pointsprod, 'goods_info' => $prodinfo));
  190. }
  191. /**
  192. * @api {POST} api/Pointprod/get_order_list 查询兑换信息
  193. * @apiVersion 1.0.0
  194. * @apiGroup Pointprod
  195. *
  196. * @apiHeader {String} X-DS-KEY 用户授权token
  197. *
  198. * @apiParam {String} pgoods_id 积分商品id
  199. * @apiParam {String} page 页码
  200. * @apiParam {String} per_page 每页数量
  201. *
  202. * @apiSuccess {String} code 返回码,10000为成功
  203. * @apiSuccess {String} message 返回消息
  204. * @apiSuccess {Object} result 返回数据
  205. * @apiSuccess {Object[]} result.order_list 订单列表 (返回字段参考pointsordergoods表)
  206. * @apiSuccess {String} result.order_list.member_avatar 用户头像
  207. * @apiSuccess {Int} result.page_total 总页数
  208. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  209. */
  210. public function get_order_list()
  211. {
  212. $pgoods_id = intval(input('param.pgoods_id'));
  213. $pointorder_model = model('pointorder');
  214. $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
  215. $where = array();
  216. $where[] = array('point_orderstate', '<>', $pointorderstate_arr['canceled'][0]);
  217. $where[] = array('pointog_goodsid', '=', $pgoods_id);
  218. $orderprod_list = $pointorder_model->getPointorderAndGoodsList($where, '*', 'pointsordergoods.pointog_recid desc', $this->pagesize);
  219. if ($orderprod_list) {
  220. $buyerid_arr = array();
  221. foreach ($orderprod_list as $k => $v) {
  222. $buyerid_arr[] = $v['point_buyerid'];
  223. }
  224. $memberlist_tmp = model('member')->getMemberList(array(array('member_id', 'in', $buyerid_arr)), 'member_id,member_avatar');
  225. $memberlist = array();
  226. if ($memberlist_tmp) {
  227. foreach ($memberlist_tmp as $v) {
  228. $memberlist[$v['member_id']] = $v;
  229. }
  230. }
  231. foreach ($orderprod_list as $k => $v) {
  232. $v['member_avatar'] = ($t = $memberlist[$v['point_buyerid']]['member_avatar']) ? ds_get_pic(ATTACH_AVATAR, $t) : ds_get_pic(ATTACH_COMMON, config('ds_config.default_user_portrait'));
  233. $orderprod_list[$k] = $v;
  234. }
  235. }
  236. $result = array_merge(array('order_list' => $orderprod_list), mobile_page(is_object($pointorder_model->page_info) ? $pointorder_model->page_info : 0));
  237. ds_json_encode(10000, '', $result);
  238. }
  239. }