LiveGoods.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * 推荐人设置
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Db;
  8. use think\facade\Lang;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  14. * 网站地址: https://www.valimart.net/
  15. * ----------------------------------------------------------------------------
  16. *
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class LiveGoods extends AdminControl {
  21. public function initialize() {
  22. parent::initialize(); // TODO: Change the autogenerated stub
  23. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/live_goods.lang.php');
  24. }
  25. public function index() {
  26. $condition = array();
  27. if ((input('param.goods_name'))) {
  28. $condition[] = array('goodscommon.goods_name', 'like', '%' . input('param.goods_name') . '%');
  29. }
  30. $fields = 'goods_id,goodscommon.gc_id,goodscommon.store_name,goodscommon.store_id,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_price,goodscommon.goods_addtime,goodscommon.goods_image,goodscommon.goods_state,goodscommon.goods_lock';
  31. $goods_model = model('goods');
  32. $goods_list = $goods_model->getGoodsUnionList($condition, $fields, 'goodscommon.goods_commonid desc', 'goodscommon.goods_commonid', 10);
  33. $minipro_live_goods_model = model('minipro_live_goods');
  34. foreach ($goods_list as $key => $val) {
  35. $goods_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
  36. $minipro_live_goods_info = $minipro_live_goods_model->getMiniproLiveGoodsInfo(array(array('goods_commonid', '=', $val['goods_commonid'])));
  37. $goods_list[$key]['minipro_live_goods_info'] = $minipro_live_goods_info;
  38. }
  39. View::assign('goods_list', $goods_list);
  40. View::assign('show_page', $goods_model->page_info->render());
  41. $this->setAdminCurItem('index');
  42. return View::fetch();
  43. }
  44. public function open() {
  45. $goods_commonid = input('param.goods_commonid');
  46. $minipro_live_goods_model = model('minipro_live_goods');
  47. //删掉后会在定时任务中重新申请
  48. $minipro_live_goods_model->delMiniproLiveGoods(array(array('goods_commonid', '=', $goods_commonid)));
  49. ds_json_encode('10000', lang('ds_common_op_succ'));
  50. }
  51. public function close() {
  52. $goods_commonid = input('param.goods_commonid');
  53. $minipro_live_goods_model = model('minipro_live_goods');
  54. $minipro_live_goods_info = $minipro_live_goods_model->getMiniproLiveGoodsInfo(array(array('goods_commonid', '=', $goods_commonid)));
  55. if ($minipro_live_goods_info) {
  56. //删除小程序商品
  57. $wechat_model = model('wechat');
  58. $wechat_model->getOneWxconfig();
  59. $accessToken = $wechat_model->getAccessToken('miniprogram', 0);
  60. if ($wechat_model->error_code) {
  61. ds_json_encode('10001', lang('get_minipro_access_token_fail') . $wechat_model->error_message);
  62. }
  63. $data = array(
  64. 'goodsId' => $minipro_live_goods_info['minipro_live_goods_result_id']
  65. );
  66. $res = http_request('https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=' . $accessToken, 'POST', $data);
  67. $res = json_decode($res, true);
  68. if (!$res || $res['errcode']) {
  69. ds_json_encode('10001', isset($res['errmsg']) ? $res['errmsg'] : lang('del_goods_fail') . $res['errcode']);
  70. }
  71. $minipro_live_goods_model->editMiniproLiveGoods(array('minipro_live_goods_close' => 1), array(array('minipro_live_goods_id', '=', $minipro_live_goods_info['minipro_live_goods_id'])));
  72. } else {
  73. $goods_model = model('goods');
  74. $goods_info = $goods_model->getGoodsCommonInfoByID($goods_commonid);
  75. if (!$goods_info) {
  76. ds_json_encode('10001', lang('goods_not_exist'));
  77. }
  78. $goods_id = Db::name('goods')->where(array(array('goods_commonid', '=', $goods_info['goods_commonid'])))->order('goods_id asc')->value('goods_id');
  79. if (!$goods_id) {
  80. ds_json_encode('10001', lang('goods_not_exist'));
  81. }
  82. $minipro_live_goods_model->addMiniproLiveGoods(array(
  83. 'store_id' => $goods_info['store_id'],
  84. 'store_name' => $goods_info['store_name'],
  85. 'goods_id' => $goods_id,
  86. 'goods_commonid' => $goods_info['goods_commonid'],
  87. 'goods_name' => $goods_info['goods_name'],
  88. 'goods_price' => $goods_info['goods_price'],
  89. 'goods_image' => $goods_info['goods_image'],
  90. 'minipro_live_goods_add_time' => TIMESTAMP,
  91. 'minipro_live_goods_close' => 1
  92. ));
  93. }
  94. ds_json_encode('10000', lang('ds_common_op_succ'));
  95. }
  96. /**
  97. * 获取卖家栏目列表,针对控制器下的栏目
  98. */
  99. protected function getAdminItemList() {
  100. $menu_array = array(
  101. array(
  102. 'name' => 'index',
  103. 'text' => lang('ds_list'),
  104. 'url' => (string) url('LiveGoods/index')
  105. ),
  106. );
  107. return $menu_array;
  108. }
  109. }