Sellerconsult.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 Sellerconsult extends MobileSeller {
  16. public function initialize() {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerconsult.lang.php');
  19. }
  20. /**
  21. * @api {POST} api/Sellerconsult/index 商品咨询列表页
  22. * @apiVersion 1.0.0
  23. * @apiGroup Sellerconsult
  24. *
  25. * @apiHeader {String} X-DS-KEY 卖家授权token
  26. *
  27. * @apiParam {String} type 回复状态 to_reply待回复 replied已回复
  28. * @apiParam {Int} ctid 咨询类型
  29. * @apiParam {String} page 页码
  30. * @apiParam {String} pagesize 每页显示数量
  31. *
  32. * @apiSuccess {String} code 返回码,10000为成功
  33. * @apiSuccess {String} message 返回消息
  34. * @apiSuccess {Object} result 返回数据
  35. * @apiSuccess {Object[]} result.consult_list 咨询列表 (参考字段参考consult表)
  36. * @apiSuccess {Object} result.consult_type 咨询类型,键为咨询类型ID
  37. * @apiSuccess {Int} result.consult_type.consulttype_id 咨询类型ID
  38. * @apiSuccess {String} result.consult_type.consulttype_introduce 咨询类型描述
  39. * @apiSuccess {String} result.consult_type.consulttype_name 咨询类型名称
  40. * @apiSuccess {Int} result.consult_type.consulttype_sort 咨询类型排序
  41. * @apiSuccess {Int} result.page_total 总页数
  42. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  43. */
  44. public function index() {
  45. $consult_model = model('consult');
  46. $goods_model = model('goods');
  47. $list_consult = array();
  48. $where = array();
  49. if (trim(input('param.type')) == 'to_reply') {
  50. $where[] = array('consult_reply', '=', '');
  51. } elseif (trim(input('param.type')) == 'replied') {
  52. $where[] = array('consult_reply', '<>', '');
  53. }
  54. if (intval(input('param.ctid')) > 0) {
  55. $where[] = array('consulttype_id', '=', intval(input('param.ctid')));
  56. }
  57. $where[] = array('store_id', '=', $this->store_info['store_id']);
  58. $list_consult = $consult_model->getConsultList($where, '*', 10);
  59. if(!empty($list_consult)){
  60. foreach($list_consult as $key => $val){
  61. $condition = array();
  62. $condition[] = array('goods_id','=',$val['goods_id']);
  63. $goodsinfo = $goods_model->getGoodsInfo($condition,'goods_image,goods_price');
  64. $list_consult[$key]['goods_image'] = goods_cthumb($goodsinfo['goods_image']);
  65. $list_consult[$key]['goods_price'] = $goodsinfo['goods_price'];
  66. }
  67. }
  68. // 咨询类型
  69. $consult_type = rkcache('consulttype', true);
  70. $result = array_merge(array('consult_list' => $list_consult, 'consult_type' => $consult_type), mobile_page($consult_model->page_info));
  71. ds_json_encode(10000, '', $result);
  72. }
  73. /**
  74. * @api {POST} api/Sellerconsult/drop_consult 商品咨询删除处理
  75. * @apiVersion 1.0.0
  76. * @apiGroup Sellerconsult
  77. *
  78. * @apiHeader {String} X-DS-KEY 卖家授权token
  79. *
  80. * @apiParam {Int} id 咨询ID
  81. *
  82. * @apiSuccess {String} code 返回码,10000为成功
  83. * @apiSuccess {String} message 返回消息
  84. * @apiSuccess {Object} result 返回数据
  85. */
  86. public function drop_consult() {
  87. $ids = trim(input('param.id'));
  88. if ($ids < 0) {
  89. ds_json_encode(10001, lang('param_error'));
  90. }
  91. $consult_model = model('consult');
  92. $id_array = explode(',', $ids);
  93. $where = array();
  94. $where[] = array('store_id', '=', $this->store_info['store_id']);
  95. $where[] = array('consult_id', 'in', $id_array);
  96. $state = $consult_model->delConsult($where);
  97. if ($state) {
  98. ds_json_encode(10000, lang('store_consult_drop_success'));
  99. } else {
  100. ds_json_encode(10001, lang('store_consult_drop_fail'));
  101. }
  102. }
  103. /**
  104. * @api {POST} api/Sellerconsult/reply_save 商品咨询回复内容的保存处理
  105. * @apiVersion 1.0.0
  106. * @apiGroup Sellerconsult
  107. *
  108. * @apiHeader {String} X-DS-KEY 卖家授权token
  109. *
  110. * @apiParam {Int} consult_id 咨询ID
  111. * @apiHeader {String} content 回复内容
  112. *
  113. * @apiSuccess {String} code 返回码,10000为成功
  114. * @apiSuccess {String} message 返回消息
  115. * @apiSuccess {Object} result 返回数据
  116. */
  117. public function reply_save() {
  118. $consult_id = intval(input('consult_id'));
  119. if ($consult_id <= 0) {
  120. ds_json_encode(10001, lang('param_error'));
  121. }
  122. $consult_model = model('consult');
  123. $update = array();
  124. $update['consult_reply'] = input('post.content');
  125. $condition = array();
  126. $condition[] = array('store_id','=',$this->store_info['store_id']);
  127. $condition[] = array('consult_id','=',$consult_id);
  128. $state = $consult_model->editConsult($condition, $update);
  129. if ($state) {
  130. $consult_info = $consult_model->getConsultInfo(array('consult_id' => $consult_id));
  131. // 发送用户消息
  132. $param = array();
  133. $param['code'] = 'consult_goods_reply';
  134. $param['member_id'] = $consult_info['member_id'];
  135. //阿里短信参数
  136. $param['ali_param'] = array(
  137. 'goods_name' => $consult_info['goods_name']
  138. );
  139. $param['ten_param'] = array(
  140. $consult_info['goods_name']
  141. );
  142. $param['param'] = array_merge($param['ali_param'], array(
  143. 'consult_url' => HOME_SITE_URL .'/Memberconsult/my_consult'
  144. ));
  145. //微信模板消息
  146. $param['weixin_param'] = array(
  147. 'url' => config('ds_config.h5_site_url') . '/pages/member/consult/ConsultList',
  148. 'data' => array(
  149. "keyword1" => array(
  150. "value" => $consult_info['consult_id'],
  151. "color" => "#333"
  152. ),
  153. "keyword2" => array(
  154. "value" => $consult_info['goods_name'],
  155. "color" => "#333"
  156. ),
  157. "keyword3" => array(
  158. "value" => $consult_info['consult_content'],
  159. "color" => "#333"
  160. )
  161. ),
  162. );
  163. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendMemberMsg','cron_value'=>serialize($param)));
  164. ds_json_encode(10000, lang('ds_common_op_succ'));
  165. } else {
  166. ds_json_encode(10001, lang('ds_common_op_fail'));
  167. }
  168. }
  169. }