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