GoodsGrab.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\goodsgrab\model;
  11. use app\model\system\Config;
  12. use app\model\BaseModel;
  13. /**
  14. * 商品采集记录
  15. */
  16. class GoodsGrab extends BaseModel
  17. {
  18. /**
  19. * 获取采集信息
  20. * @param $condition
  21. * @param string $field
  22. * @return array
  23. */
  24. public function getGoodsGrabInfo($condition, $field = '*')
  25. {
  26. $info = model('goods_grab')->getInfo($condition, $field);
  27. return $this->success($info);
  28. }
  29. /**
  30. * 获取商品采集记录
  31. * @param array $condition
  32. * @param string $field
  33. * @param string $order
  34. * @param null $limit
  35. * @return array
  36. */
  37. public function getGoodsGrabList($condition = [], $field = '*', $order = 'grab_id desc', $limit = null)
  38. {
  39. $list = model('goods_grab')->getList($condition, $field, $order, '', '', '', $limit);
  40. return $this->success($list);
  41. }
  42. /**
  43. * 获取商品采集分页记录
  44. *
  45. * @param array $condition
  46. * @param number $page
  47. * @param string $page_size
  48. * @param string $order
  49. * @param string $field
  50. */
  51. public function getGoodsGrabPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'grab_id desc', $field = '*')
  52. {
  53. $list = model('goods_grab')->pageList($condition, $field, $order, $page, $page_size);
  54. return $this->success($list);
  55. }
  56. /**
  57. * 获取采集明细分页记录
  58. * @param array $condition
  59. * @param int $page
  60. * @param int $page_size
  61. * @param string $order
  62. * @param string $field
  63. * @return array
  64. */
  65. public function getGoodsGrabDetailPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  66. {
  67. $list = model('goods_grab_detail')->pageList($condition, $field, $order, $page, $page_size);
  68. return $this->success($list);
  69. }
  70. /**
  71. * 删除采集信息
  72. * @param $condition
  73. * @param string $field
  74. * @return array
  75. */
  76. public function delGoodsGrab($condition)
  77. {
  78. model('goods_grab')->startTrans();
  79. try{
  80. //删除采集表信息
  81. model('goods_grab')->delete($condition);
  82. model('goods_grab_detail')->delete($condition);
  83. model('goods_grab')->commit();
  84. return $this->success();
  85. }catch(\Exception $e){
  86. model()->rollback();
  87. return $this->error('',$e->getMessage());
  88. }
  89. }
  90. /************************************ 商品采集设置 start **********************************************************/
  91. /**
  92. * 商品采集设置
  93. * @param $data
  94. * @return array
  95. */
  96. public function setGoodsGrabConfig($data,$site_id)
  97. {
  98. $config = new Config();
  99. $res = $config->setConfig($data, '商品采集设置', 1, [['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'GOODSGRAB_CONFIG']]);
  100. return $this->success($res);
  101. }
  102. /**
  103. * 获取商品采集设置
  104. * @return array
  105. */
  106. public function getGoodsGrabConfig($site_id)
  107. {
  108. $config = new Config();
  109. $res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', 'shop'], ['config_key', '=', 'GOODSGRAB_CONFIG']]);
  110. if (empty($res['data']['value'])) {
  111. $res['data']['value'] = [
  112. 'type' => '99api',
  113. 'key' => ''
  114. ];
  115. }
  116. return $res;
  117. }
  118. /************************************ 商品采集设置 end **********************************************************/
  119. }