GoodsService.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace addons\WechatMini\services\live;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\components\Service;
  6. use addons\WechatMini\common\models\live\Goods;
  7. /**
  8. * Class GoodsService
  9. * @package addons\WechatMini\services\live
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class GoodsService extends Service
  13. {
  14. public function syncByRoom($goods)
  15. {
  16. }
  17. /**
  18. * @param $offset
  19. * @param $count
  20. * @param $auditStatus
  21. * @return true|void
  22. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  23. * @throws \GuzzleHttp\Exception\GuzzleException
  24. */
  25. public function sync($offset, $count, $auditStatus = 1)
  26. {
  27. $lists = Yii::$app->wechat->miniProgram->broadcast->getApproved([
  28. 'offset' => $offset,
  29. 'limit' => $count,
  30. 'status' => $auditStatus, // 商品状态,0:未审核。1:审核中,2:审核通过,3:审核驳回
  31. ]);
  32. if (empty($lists['goods'])) {
  33. return true;
  34. }
  35. $rows = [];
  36. foreach ($lists['goods'] as $goods) {
  37. // 插入产品
  38. $rows[] = [
  39. 'merchant_id' => Yii::$app->services->merchant->getNotNullId(),
  40. 'store_id' => Yii::$app->services->store->getNotNullId(),
  41. 'cover_img' => $goods['coverImgUrl'],
  42. 'goods_id' => $goods['goodsId'],
  43. 'name' => $goods['name'],
  44. 'url' => $goods['url'],
  45. 'price' => $goods['price'],
  46. 'price_two' => $goods['price2'],
  47. 'price_type' => $goods['priceType'],
  48. 'third_party_tag' => $goods['thirdPartyTag'],
  49. 'third_party_appid' => $goods['thirdPartyAppid'],
  50. 'audit_status' => $auditStatus,
  51. 'status' => StatusEnum::ENABLED,
  52. 'created_at' => time(),
  53. 'updated_at' => time()
  54. ];
  55. }
  56. if (!empty($rows)) {
  57. $field = array_keys($rows[0]);
  58. !empty($rows) && Yii::$app->db->createCommand()->batchInsert(Goods::tableName(), $field, $rows)->execute();
  59. }
  60. }
  61. }
粤ICP备19079148号