Pointprod.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 积分兑换控制器
  15. */
  16. class Pointprod extends MobileMall {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/pointprod.lang.php');
  20. //判断系统是否开启积分兑换功能
  21. if (config('ds_config.points_isuse') != 1 || config('ds_config.pointprod_isuse') != 1) {
  22. ds_json_encode(10001, lang('pointshop_unavailable'));
  23. }
  24. }
  25. public function index() {
  26. $this->plist();
  27. }
  28. /**
  29. * @api {POST} api/Pointprod/plist 积分商品列表
  30. * @apiVersion 1.0.0
  31. * @apiGroup Pointprod
  32. *
  33. * @apiHeader {String} X-DS-KEY 用户授权token
  34. *
  35. * @apiParam {String} level 会员级别
  36. * @apiParam {String} isable 仅我能兑换 0否 1是
  37. * @apiParam {String} points_min 积分从
  38. * @apiParam {String} points_max 积分到
  39. * @apiParam {String} orderby 排序 stimedesc积分兑换开始时间降序 stimeasc积分兑换开始时间升序 pointsdesc兑换积分降序 pointsasc兑换积分升序
  40. * @apiParam {String} page 页码
  41. * @apiParam {String} per_page 每页数量
  42. *
  43. * @apiSuccess {String} code 返回码,10000为成功
  44. * @apiSuccess {String} message 返回消息
  45. * @apiSuccess {Object} result 返回数据
  46. * @apiSuccess {Object[]} result.goods_list 积分商品列表 (返回字段参考pointsgoods表)
  47. * @apiSuccess {String} result.goods_list.ex_state 兑换状态代码 end不可兑换willbe即将开始going进行中
  48. * @apiSuccess {Int} result.goods_list.pgoods_limitgradename 所需用户等级
  49. * @apiSuccess {Object} result.grade_list 返回数据,键为等级ID
  50. * @apiSuccess {Int} result.grade_list.exppoints 所需积分
  51. * @apiSuccess {Int} result.grade_list.level 等级ID
  52. * @apiSuccess {String} result.grade_list.level_name 等级名称
  53. * @apiSuccess {String} result.ww json化的查询条件
  54. * @apiSuccess {Int} result.page_total 总页数
  55. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  56. */
  57. public function plist() {
  58. $pointprod_model = model('pointprod');
  59. //展示状态
  60. $pgoodsshowstate_arr = $pointprod_model->getPgoodsShowState();
  61. //开启状态
  62. $pgoodsopenstate_arr = $pointprod_model->getPgoodsOpenState();
  63. $member_model = model('member');
  64. //查询会员等级
  65. $membergrade_arr = $member_model->getMemberGradeArr();
  66. //查询兑换服务列表
  67. $where = array();
  68. $where[] = array('pgoods_show', '=', $pgoodsshowstate_arr['show'][0]);
  69. $where[] = array('pgoods_state', '=', $pgoodsopenstate_arr['open'][0]);
  70. //会员级别
  71. $level_filter = array();
  72. if (input('level')) {
  73. $level_filter['search'] = intval(input('level'));
  74. }
  75. if (input('isable') == 1) {
  76. if ($memberid = $this->getMemberIdIfExists()) {
  77. $member_infotmp = model('member')->getMemberInfoByID($memberid);
  78. //当前登录会员等级信息
  79. $membergrade_info = $member_model->getOneMemberGrade($member_infotmp['member_exppoints'], true);
  80. $this->member_info = array_merge($member_infotmp, $membergrade_info);
  81. }
  82. }
  83. if (input('isable') == 1 && isset($this->member_info['level'])) {
  84. $level_filter['isable'] = intval($this->member_info['level']);
  85. }
  86. if (count($level_filter) > 0) {
  87. if (isset($level_filter['search']) && isset($level_filter['isable'])) {
  88. $where[] = array('pgoods_limitmgrade', '=', $level_filter['search']);
  89. $where[] = array('pgoods_limitmgrade', '<=', $level_filter['isable']);
  90. } elseif (isset($level_filter['search'])) {
  91. $where[] = array('pgoods_limitmgrade', '=', $level_filter['search']);
  92. } elseif (isset($level_filter['isable'])) {
  93. $where[] = array('pgoods_limitmgrade', '<=', $level_filter['isable']);
  94. }
  95. }
  96. //查询仅我能兑换和所需积分
  97. $points_filter = array();
  98. if (input('isable') == 1 && isset($this->member_info['level'])) {
  99. $points_filter['isable'] = $this->member_info['member_points'];
  100. }
  101. if (input('points_min') > 0) {
  102. $points_filter['min'] = intval(input('points_min'));
  103. }
  104. if (input('points_max') > 0) {
  105. $points_filter['max'] = intval(input('points_max'));
  106. }
  107. if (count($points_filter) > 0) {
  108. asort($points_filter);
  109. if (count($points_filter) > 1) {
  110. $points_filter = array_values($points_filter);
  111. $where[] = array('pgoods_points', 'between', array($points_filter[0], $points_filter[1]));
  112. } else {
  113. if ($points_filter['min']) {
  114. $where[] = array('pgoods_points', '>=', $points_filter['min']);
  115. } elseif ($points_filter['max']) {
  116. $where[] = array('pgoods_points', '<=', $points_filter['max']);
  117. } elseif ($points_filter['isable']) {
  118. $where[] = array('pgoods_points', '<=', $points_filter['isable']);
  119. }
  120. }
  121. }
  122. //排序
  123. switch (input('orderby')) {
  124. case 'stimedesc':
  125. $orderby = 'pgoods_starttime desc,';
  126. break;
  127. case 'stimeasc':
  128. $orderby = 'pgoods_starttime asc,';
  129. break;
  130. case 'pointsdesc':
  131. $orderby = 'pgoods_points desc,';
  132. break;
  133. case 'pointsasc':
  134. $orderby = 'pgoods_points asc,';
  135. break;
  136. default:
  137. $orderby = '';
  138. }
  139. $orderby .= 'pgoods_sort asc,pgoods_id desc';
  140. $pageSize = 10;
  141. $pointprod_list = $pointprod_model->getPointProdList($where, "*", $orderby, '', $pageSize);
  142. $page_count = $pointprod_model->page_info;
  143. $result = array_merge(array('goods_list' => $pointprod_list, 'grade_list' => $membergrade_arr, 'ww' => json_encode($where)), mobile_page($page_count));
  144. ds_json_encode(10000, '', $result);
  145. }
  146. /**
  147. * @api {POST} api/Pointprod/pinfo 积分商品详情
  148. * @apiVersion 1.0.0
  149. * @apiGroup Pointprod
  150. *
  151. * @apiHeader {String} X-DS-KEY 用户授权token
  152. *
  153. * @apiParam {String} id 积分商品id
  154. *
  155. * @apiSuccess {String} code 返回码,10000为成功
  156. * @apiSuccess {String} message 返回消息
  157. * @apiSuccess {Object} result 返回数据
  158. * @apiSuccess {Object[]} result.goods_commend_list 推荐积分商品列表 (返回字段参考pointsgoods表)
  159. * @apiSuccess {String} result.goods_commend_list.ex_state 兑换状态代码 end不可兑换willbe即将开始going进行中
  160. * @apiSuccess {Int} result.goods_commend_list.pgoods_limitgradename 所需用户等级
  161. * @apiSuccess {Object} result.goods_info 积分商品信息 (返回字段参考pointsgoods表)
  162. * @apiSuccess {String} result.goods_info.ex_state 兑换状态代码 end不可兑换willbe即将开始going进行中
  163. * @apiSuccess {Int} result.goods_info.pgoods_limitgradename 所需用户等级
  164. */
  165. public function pinfo() {
  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. $pgoods_id = intval(input('param.pgoods_id'));
  212. $pointorder_model = model('pointorder');
  213. $pointorderstate_arr = $pointorder_model->getPointorderStateBySign();
  214. $where = array();
  215. $where[] = array('point_orderstate', '<>', $pointorderstate_arr['canceled'][0]);
  216. $where[] = array('pointog_goodsid', '=', $pgoods_id);
  217. $orderprod_list = $pointorder_model->getPointorderAndGoodsList($where, '*', 'pointsordergoods.pointog_recid desc', $this->pagesize);
  218. if ($orderprod_list) {
  219. $buyerid_arr = array();
  220. foreach ($orderprod_list as $k => $v) {
  221. $buyerid_arr[] = $v['point_buyerid'];
  222. }
  223. $memberlist_tmp = model('member')->getMemberList(array(array('member_id', 'in', $buyerid_arr)), 'member_id,member_avatar');
  224. $memberlist = array();
  225. if ($memberlist_tmp) {
  226. foreach ($memberlist_tmp as $v) {
  227. $memberlist[$v['member_id']] = $v;
  228. }
  229. }
  230. foreach ($orderprod_list as $k => $v) {
  231. $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'));
  232. $orderprod_list[$k] = $v;
  233. }
  234. }
  235. $result = array_merge(array('order_list' => $orderprod_list), mobile_page(is_object($pointorder_model->page_info) ? $pointorder_model->page_info : 0));
  236. ds_json_encode(10000, '', $result);
  237. }
  238. }
  239. ?>