Bargain.php 7.5 KB

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