Sellerconsult.php 7.3 KB

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