Bargain.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 Bargain extends MobileMall {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path().'home/lang/'.config('lang.default_lang').'/bargain.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Bargain/get_list 砍价活动列表
  23. * @apiVersion 1.0.0
  24. * @apiGroup Bargain
  25. *
  26. * @apiHeader {String} X-DS-KEY 用户授权token
  27. *
  28. * @apiParam {Int} page 页码
  29. * @apiParam {Int} per_page 每页数量
  30. *
  31. * @apiSuccess {String} code 返回码,10000为成功
  32. * @apiSuccess {String} message 返回消息
  33. * @apiSuccess {Object} result 返回数据
  34. * @apiSuccess {Object[]} result.bargain_list 砍价活动列表
  35. * @apiSuccess {String} result.bargain_list.bargain_goods_image_url 商品图片
  36. */
  37. public function get_list() {
  38. $pbargain_model = model('pbargain');
  39. $goods_model = model('goods');
  40. $pbargainorder_model=model('pbargainorder');
  41. $bargain_list = $pbargain_model->getOnlineBargainList(array(), $this->pagesize);
  42. foreach($bargain_list as $key => $val){
  43. $goods_info=$goods_model->getGoodsInfoByID($val['bargain_goods_id']);
  44. if(!$goods_info || $goods_info['goods_state']!=1 || $goods_info['goods_verify']!=1){
  45. unset($bargain_list[$key]);
  46. continue;
  47. }
  48. $bargain_list[$key]['bargain_goods_image_url'] = goods_cthumb($val['bargain_goods_image'], 480, $val['store_id']);
  49. //获取已砍数量
  50. $pbargainorder_count = $pbargainorder_model->getPbargainorderCount(array('bargain_id' => $val['bargain_id'],'bargainorder_state' => 2));
  51. if($goods_info['goods_storage']){
  52. $order_percent=$pbargainorder_count/$goods_info['goods_storage']*100;
  53. if($order_percent>100){
  54. $order_percent=100;
  55. }
  56. }else{
  57. $order_percent=100;
  58. }
  59. $bargain_list[$key]['order_percent'] = $order_percent;
  60. $bargain_list[$key]['order_count'] = $pbargainorder_count;
  61. }
  62. $result = array_merge(array('bargain_list' => $bargain_list), mobile_page($pbargain_model->page_info));
  63. ds_json_encode(10000, '', $result);
  64. }
  65. /**
  66. * @api {POST} api/Bargain/get_info 砍价活动详情
  67. * @apiVersion 1.0.0
  68. * @apiGroup Bargain
  69. *
  70. * @apiHeader {String} X-DS-KEY 用户授权token
  71. *
  72. * @apiParam {Int} bargain_id 砍价id
  73. *
  74. * @apiSuccess {String} code 返回码,10000为成功
  75. * @apiSuccess {String} message 返回消息
  76. * @apiSuccess {Object} result 返回数据
  77. * @apiSuccess {Object} result.bargain_info 砍价信息
  78. */
  79. public function get_info() {
  80. $bargain_id = input('param.bargain_id');
  81. if (!$bargain_id) {
  82. ds_json_encode(10001, lang('param_error'));
  83. }
  84. $pbargain_model = model('pbargain');
  85. $bargain_info = $pbargain_model->getOnlineBargainInfoByID($bargain_id);
  86. if (!$bargain_info) {
  87. ds_json_encode(10001, lang('bargain_not_exist'));
  88. }
  89. ds_json_encode(10000, '', array('bargain_info' => $bargain_info));
  90. }
  91. /**
  92. * @api {POST} api/Bargain/get_order_info 用户砍价活动详情
  93. * @apiVersion 1.0.0
  94. * @apiGroup Bargain
  95. *
  96. * @apiHeader {String} X-DS-KEY 用户授权token
  97. *
  98. * @apiParam {Int} bargainorder_id 用户砍价id
  99. *
  100. * @apiSuccess {String} code 返回码,10000为成功
  101. * @apiSuccess {String} message 返回消息
  102. * @apiSuccess {Object} result 返回数据
  103. * @apiSuccess {Object} result.bargainorder_info 用户砍价信息
  104. * @apiSuccess {String} result.bargainorder_initiator_avatar 用户头像
  105. * @apiSuccess {String} result.bargain_goods_image_url 商品图片
  106. * @apiSuccess {Float} result.bargain_goods_diff_price 已砍金额
  107. * @apiSuccess {Float} result.bargain_percent 砍价进度
  108. */
  109. public function get_order_info() {
  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. $bargainorder_id = input('param.bargainorder_id');
  152. if (!$bargainorder_id) {
  153. ds_json_encode(10001, lang('param_error'));
  154. }
  155. $pbargainlog_model = model('pbargainlog');
  156. $bargainlog_list = $pbargainlog_model->getPbargainlogList(array('bargainorder_id'=>$bargainorder_id), $this->pagesize);
  157. foreach($bargainlog_list as $key => $val){
  158. $bargainlog_list[$key]['pbargainlog_member_avatar']=get_member_avatar_for_id($val['pbargainlog_member_id']);
  159. }
  160. $result = array_merge(array('bargainlog_list' => $bargainlog_list), mobile_page($pbargainlog_model->page_info));
  161. ds_json_encode(10000, '', $result);
  162. }
  163. }