LiveGoods.php 5.4 KB

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