Sellerconsult.php 7.0 KB

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