Bargain.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 砍价活动控制器
  10. */
  11. class Bargain extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/bargain.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Bargain/get_list 砍价活动列表
  20. * @apiVersion 1.0.0
  21. * @apiGroup Bargain
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiParam {Int} page 页码
  26. * @apiParam {Int} per_page 每页数量
  27. *
  28. * @apiSuccess {String} code 返回码,10000为成功
  29. * @apiSuccess {String} message 返回消息
  30. * @apiSuccess {Object} result 返回数据
  31. * @apiSuccess {Object[]} result.bargain_list 砍价活动列表
  32. * @apiSuccess {String} result.bargain_list.bargain_goods_image_url 商品图片
  33. */
  34. public function get_list()
  35. {
  36. $pbargain_model = model('pbargain');
  37. $goods_model = model('goods');
  38. $pbargainorder_model = model('pbargainorder');
  39. $bargain_list = $pbargain_model->getOnlineBargainList(array(), $this->pagesize);
  40. foreach ($bargain_list as $key => $val) {
  41. $goods_info = $goods_model->getGoodsInfoByID($val['bargain_goods_id']);
  42. if (!$goods_info || $goods_info['goods_state'] != 1 || $goods_info['goods_verify'] != 1) {
  43. unset($bargain_list[$key]);
  44. continue;
  45. }
  46. $bargain_list[$key]['bargain_goods_image_url'] = goods_cthumb($val['bargain_goods_image'], 480, $val['store_id']);
  47. //获取已砍数量
  48. $pbargainorder_count = $pbargainorder_model->getPbargainorderCount(array('bargain_id' => $val['bargain_id'], 'bargainorder_state' => 2));
  49. if ($goods_info['goods_storage']) {
  50. $order_percent = $pbargainorder_count / $goods_info['goods_storage'] * 100;
  51. if ($order_percent > 100) {
  52. $order_percent = 100;
  53. }
  54. } else {
  55. $order_percent = 100;
  56. }
  57. $bargain_list[$key]['order_percent'] = $order_percent;
  58. $bargain_list[$key]['order_count'] = $pbargainorder_count;
  59. }
  60. $result = array_merge(array('bargain_list' => $bargain_list), mobile_page($pbargain_model->page_info));
  61. ds_json_encode(10000, '', $result);
  62. }
  63. /**
  64. * @api {POST} api/Bargain/get_info 砍价活动详情
  65. * @apiVersion 1.0.0
  66. * @apiGroup Bargain
  67. *
  68. * @apiHeader {String} X-DS-KEY 用户授权token
  69. *
  70. * @apiParam {Int} bargain_id 砍价id
  71. *
  72. * @apiSuccess {String} code 返回码,10000为成功
  73. * @apiSuccess {String} message 返回消息
  74. * @apiSuccess {Object} result 返回数据
  75. * @apiSuccess {Object} result.bargain_info 砍价信息
  76. */
  77. public function get_info()
  78. {
  79. $bargain_id = input('param.bargain_id');
  80. if (!$bargain_id) {
  81. ds_json_encode(10001, lang('param_error'));
  82. }
  83. $pbargain_model = model('pbargain');
  84. $bargain_info = $pbargain_model->getOnlineBargainInfoByID($bargain_id);
  85. if (!$bargain_info) {
  86. ds_json_encode(10001, lang('bargain_not_exist'));
  87. }
  88. ds_json_encode(10000, '', array('bargain_info' => $bargain_info));
  89. }
  90. /**
  91. * @api {POST} api/Bargain/get_order_info 用户砍价活动详情
  92. * @apiVersion 1.0.0
  93. * @apiGroup Bargain
  94. *
  95. * @apiHeader {String} X-DS-KEY 用户授权token
  96. *
  97. * @apiParam {Int} bargainorder_id 用户砍价id
  98. *
  99. * @apiSuccess {String} code 返回码,10000为成功
  100. * @apiSuccess {String} message 返回消息
  101. * @apiSuccess {Object} result 返回数据
  102. * @apiSuccess {Object} result.bargainorder_info 用户砍价信息
  103. * @apiSuccess {String} result.bargainorder_initiator_avatar 用户头像
  104. * @apiSuccess {String} result.bargain_goods_image_url 商品图片
  105. * @apiSuccess {Float} result.bargain_goods_diff_price 已砍金额
  106. * @apiSuccess {Float} result.bargain_percent 砍价进度
  107. */
  108. public function get_order_info()
  109. {
  110. $bargainorder_id = input('param.bargainorder_id');
  111. if (!$bargainorder_id) {
  112. ds_json_encode(10001, lang('param_error'));
  113. }
  114. $pbargainorder_model = model('pbargainorder');
  115. $bargainorder_info = $pbargainorder_model->getOnePbargainorder(array('bargainorder_id' => $bargainorder_id), true);
  116. if (!$bargainorder_info) {
  117. ds_json_encode(10001, lang('bargain_not_exist'));
  118. }
  119. $bargainorder_info['bargain_if_add'] = true;
  120. //判断是否已经砍过价
  121. $member_id = $this->getMemberIdIfExists();
  122. if ($member_id) {
  123. if (model('pbargainlog')->getOnePbargainlog(array('bargainorder_id' => $bargainorder_id, 'pbargainlog_member_id' => $member_id))) {
  124. $bargainorder_info['bargain_if_add'] = false;
  125. }
  126. }
  127. $bargainorder_info['bargainorder_initiator_avatar'] = get_member_avatar_for_id($bargainorder_info['bargainorder_initiator_id']);
  128. $bargainorder_info['bargain_goods_image_url'] = goods_cthumb($bargainorder_info['bargain_goods_image'], 480, $bargainorder_info['store_id']);
  129. $bargainorder_info['bargain_goods_diff_price'] = number_format($bargainorder_info['bargain_goods_price'] - $bargainorder_info['bargainorder_current_price'], '2');
  130. $bargainorder_info['bargain_percent'] = $bargainorder_info['bargainorder_times'] / $bargainorder_info['bargain_total'] * 100;
  131. ds_json_encode(10000, '', array('bargainorder_info' => $bargainorder_info));
  132. }
  133. /**
  134. * @api {POST} api/Bargain/get_log_list 砍价记录列表
  135. * @apiVersion 1.0.0
  136. * @apiGroup Bargain
  137. *
  138. * @apiHeader {String} X-DS-KEY 用户授权token
  139. *
  140. * @apiParam {Int} bargainorder_id 用户砍价id
  141. * @apiParam {Int} page 页码
  142. * @apiParam {Int} per_page 每页数量
  143. *
  144. * @apiSuccess {String} code 返回码,10000为成功
  145. * @apiSuccess {String} message 返回消息
  146. * @apiSuccess {Object} result 返回数据
  147. * @apiSuccess {Object[]} result.bargainlog_list 砍价记录
  148. * @apiSuccess {String} result.bargainlog_list.bargainorder_initiator_avatar 用户头像
  149. */
  150. public function get_log_list()
  151. {
  152. $bargainorder_id = input('param.bargainorder_id');
  153. if (!$bargainorder_id) {
  154. ds_json_encode(10001, lang('param_error'));
  155. }
  156. $pbargainlog_model = model('pbargainlog');
  157. $bargainlog_list = $pbargainlog_model->getPbargainlogList(array('bargainorder_id' => $bargainorder_id), $this->pagesize);
  158. foreach ($bargainlog_list as $key => $val) {
  159. $bargainlog_list[$key]['pbargainlog_member_avatar'] = get_member_avatar_for_id($val['pbargainlog_member_id']);
  160. }
  161. $result = array_merge(array('bargainlog_list' => $bargainlog_list), mobile_page($pbargainlog_model->page_info));
  162. ds_json_encode(10000, '', $result);
  163. }
  164. }