ProductController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\erp;
  12. use app\jobs\product\ProductSyncErp;
  13. use app\Request;
  14. use crmeb\services\erp\Erp as ErpServices;
  15. use crmeb\services\erp\storage\jushuitan\Product as ProductService;
  16. use think\Response;
  17. /**
  18. * 商品类
  19. * Class ProductController
  20. * @package app\controller\erp
  21. */
  22. class ProductController
  23. {
  24. /*** @var ProductService */
  25. protected $services;
  26. public function __construct(ErpServices $services)
  27. {
  28. $this->services = $services->serviceDriver('product');
  29. }
  30. /**
  31. * 使用spu同步商品
  32. * @param Request $request
  33. * @return mixed
  34. * @throws \Exception
  35. */
  36. public function syncProduct(Request $request)
  37. {
  38. [$spuStr] = $request->getMore([
  39. ['spu_str', ''],
  40. ], true);
  41. if (empty($spuStr)) {
  42. return app('json')->fail('请输入ERP商品SPU');
  43. }
  44. $spuArr = explode(',', $spuStr);
  45. foreach ($spuArr as $item) {
  46. // 获取商品
  47. ProductSyncErp::dispatchDo('productFromErp', [$item]);
  48. }
  49. return app('json')->success('正在同步中,请稍后查看');
  50. }
  51. /**
  52. * 使用sku同步库存
  53. * @param Request $request
  54. * @return mixed
  55. * @throws \Exception
  56. */
  57. public function syncStock(Request $request)
  58. {
  59. [$ids] = $request->getMore([
  60. ['ids', ''],
  61. ], true);
  62. if (empty($ids)) {
  63. return app('json')->fail('请选择商品');
  64. }
  65. $idArr = explode(',', $ids);
  66. $data = array_chunk($idArr, 1);
  67. foreach ($data as $item) {
  68. // 获取库存
  69. ProductSyncErp::dispatchDo('stockFromErp', [$item]);
  70. }
  71. return app('json')->success('正在同步中,请稍后查看');
  72. }
  73. }