OldGoodsController.php 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. <?php
  2. namespace app\frontend\modules\goods\controllers;
  3. use app\backend\modules\goods\models\Brand;
  4. use app\common\components\ApiController;
  5. use app\common\components\BaseController;
  6. use app\common\exceptions\AppException;
  7. use app\common\exceptions\MemberNotLoginException;
  8. use app\common\facades\Setting;
  9. use app\common\models\Category;
  10. use app\common\models\goods\Privilege;
  11. use app\common\models\OrderGoods;
  12. use app\frontend\models\Member;
  13. use app\frontend\modules\goods\models\Goods;
  14. use app\common\models\GoodsSpecItem;
  15. use app\common\services\goods\SaleGoods;
  16. use app\common\services\goods\VideoDemandCourseGoods;
  17. use app\common\models\MemberShopInfo;
  18. use app\frontend\modules\member\controllers\ServiceController;
  19. use app\frontend\modules\member\services\MemberService;
  20. use Illuminate\Support\Facades\DB;
  21. use Monolog\Handler\IFTTTHandler;
  22. use Yunshop\Commission\Common\Services\GoodsDetailService;
  23. use Yunshop\Designer\models\ViewSet;
  24. use Yunshop\FreightPricing\models\ContentModel;
  25. use Yunshop\GoodsLink\services\GetGoodsDocService;
  26. use Yunshop\MarketSub\models\MarketSubGoods;
  27. use Yunshop\ProductMarket\models\ProductMarketGoodsModel;
  28. use Yunshop\Room\models\Room;
  29. use Yunshop\ServiceFee\models\ServiceFeeModel;
  30. use Yunshop\StoreCashier\common\services\CustomerService;
  31. use Yunshop\StoreCashier\store\models\StoreGoods;
  32. use Yunshop\TeamDividend\Common\Services\TeamDividendGoodsDetailService;
  33. use Yunshop\Commission\models\Agents;
  34. use Yunshop\Love\Common\Models\GoodsLove;
  35. use app\frontend\modules\coupon\models\Coupon;
  36. use app\frontend\modules\coupon\controllers\MemberCouponController;
  37. use app\common\services\goods\LeaseToyGoods;
  38. use Yunshop\Supplier\common\models\SupplierGoods;
  39. use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
  40. use app\common\models\MemberLevel;
  41. use app\common\models\MemberGroup;
  42. use Yunshop\StoreCashier\common\models\StoreSetting;
  43. use app\frontend\modules\goods\models\Comment;
  44. use Yunshop\TeamSales\common\services\GoodsListService;
  45. use Yunshop\Decorate\models\DecorateTempletModel;
  46. use Yunshop\WxVideoLink\common\model\WxVideoLikeSetModel;
  47. /**
  48. * Created by PhpStorm.
  49. * Author: 芸众商城 www.yunzshop.com
  50. * Date: 2017/3/3
  51. * Time: 22:16
  52. */
  53. class OldGoodsController extends GoodsController
  54. {
  55. protected $publicAction = ['getRecommendGoods'];
  56. protected $ignoreAction = ['getRecommendGoods'];
  57. // 拆分getGoods方法,分离和插件相关的部分,只提取属于商品的信息。和插件相关的部分在getGoods中处理
  58. protected function _getGoods($id, $integrated = null)
  59. {
  60. $goods_model = \app\common\modules\shop\ShopConfig::current()->get('goods.models.commodity_classification');
  61. $goods_model = new $goods_model;
  62. try {
  63. $member = Member::current()->yzMember;
  64. } catch (MemberNotLoginException $e) {
  65. if (\YunShop::request()->type == 1) {
  66. return;
  67. }
  68. throw new MemberNotLoginException($e->getMessage(), $e->getData());
  69. }
  70. $goodsModel = $goods_model->uniacid()
  71. ->with([
  72. 'hasManyParams' => function ($query) {
  73. return $query->select('goods_id', 'title', 'value')->orderby('displayorder', 'asc');
  74. },
  75. 'hasManySpecs' => function ($query) {
  76. return $query->select('id', 'goods_id', 'title', 'description');
  77. },
  78. 'hasManyOptions' => function ($query) {
  79. return $query->select('id', 'goods_id', 'title', 'thumb', 'product_price', 'market_price', 'stock', 'specs', 'weight');
  80. },
  81. 'hasManyDiscount' => function ($query) use ($member) {
  82. return $query->where('level_id', $member->level_id);
  83. },
  84. 'hasOneBrand' => function ($query) {
  85. return $query->select('id', 'logo', 'name', 'desc');
  86. },
  87. 'hasOneShare',
  88. 'hasOneGoodsDispatch',
  89. 'hasOnePrivilege',
  90. 'hasOneSale',
  91. 'hasOneGoodsCoupon',
  92. 'hasOneInvitePage',
  93. 'hasOneGoodsLimitBuy',
  94. 'hasOneGoodsVideo',
  95. ])
  96. ->find($id);
  97. $goodsModel->vip_level_status;
  98. if (!$goodsModel) {
  99. if (is_null($integrated)) {
  100. return $this->errorJson('商品不存在.');
  101. } else {
  102. return show_json(0, '商品不存在.');
  103. }
  104. }
  105. //限时购 todo 后期优化 应该是前端优化
  106. // $current_time = time();
  107. // if (!is_null($goodsModel->hasOneGoodsLimitBuy)) {
  108. // if ($goodsModel->hasOneGoodsLimitBuy->end_time < $current_time && $goodsModel->hasOneGoodsLimitBuy->status == 1) {
  109. // $goodsModel->status = 0;
  110. // $goodsModel->save();
  111. // }
  112. // }
  113. $current_time = time();
  114. if (!is_null($goodsModel->hasOneGoodsLimitBuy)) {
  115. if ($goodsModel->hasOneGoodsLimitBuy->end_time < $current_time && $goodsModel->hasOneGoodsLimitBuy->status == 1) {
  116. if (is_null($integrated)) {
  117. return $this->errorJson('商品限时购已到期.');
  118. } else {
  119. return show_json(0, '商品限时购已到期.');
  120. }
  121. }
  122. }
  123. if (!$goodsModel->status) {
  124. if (is_null($integrated)) {
  125. return $this->errorJson('商品已下架.');
  126. } else {
  127. return show_json(0, '商品已下架.');
  128. }
  129. }
  130. $goodsModel->is_added = \Setting::get('shop.member.added') ?: 1;
  131. //商品品牌处理
  132. if ($goodsModel->hasOneBrand) {
  133. $goodsModel->hasOneBrand->desc = html_entity_decode($goodsModel->hasOneBrand->desc);
  134. $goodsModel->hasOneBrand->logo = yz_tomedia($goodsModel->hasOneBrand->logo);
  135. }
  136. //商品规格图片处理
  137. if ($goodsModel->hasManyOptions && $goodsModel->hasManyOptions->toArray()) {
  138. foreach ($goodsModel->hasManyOptions as &$item) {
  139. $item->thumb = replace_yunshop(yz_tomedia($item->thumb));
  140. }
  141. }
  142. $goodsModel->content = html_entity_decode($goodsModel->content);
  143. if ($goodsModel->has_option) {
  144. $goodsModel->min_price = $goodsModel->hasManyOptions->min("product_price");
  145. $goodsModel->max_price = $goodsModel->hasManyOptions->max("product_price");
  146. $goodsModel->stock = $goodsModel->hasManyOptions->sum('stock');
  147. }
  148. foreach ($goodsModel->hasManySpecs as &$spec) {
  149. $spec['specitem'] = GoodsSpecItem::select('id', 'title', 'specid', 'thumb')->where('show', 1)->where('specid', $spec['id'])->orderBy('display_order', 'asc')->get();
  150. foreach ($spec['specitem'] as &$specitem) {
  151. $specitem['thumb'] = yz_tomedia($specitem['thumb']);
  152. }
  153. }
  154. $goodsModel->setHidden(
  155. [
  156. 'deleted_at',
  157. 'created_at',
  158. 'updated_at',
  159. 'cost_price',
  160. 'real_sales',
  161. 'is_deleted',
  162. 'reduce_stock_method',
  163. ]);
  164. //商品图片处理
  165. if ($goodsModel->thumb) {
  166. $goodsModel->thumb = yz_tomedia($goodsModel->thumb);
  167. }
  168. if ($goodsModel->thumb_url) {
  169. $thumb_url = unserialize($goodsModel->thumb_url);
  170. foreach ($thumb_url as &$item) {
  171. $item = yz_tomedia($item);
  172. }
  173. $goodsModel->thumb_url = $thumb_url;
  174. }
  175. //商品视频处理
  176. if (!is_null($goodsModel->hasOneGoodsVideo) && $goodsModel->hasOneGoodsVideo->goods_video) {
  177. $goodsModel->goods_video = yz_tomedia($goodsModel->hasOneGoodsVideo->goods_video);
  178. $goodsModel->video_image = $goodsModel->hasOneGoodsVideo->video_image ? yz_tomedia($goodsModel->hasOneGoodsVideo->video_image) : yz_tomedia($goodsModel->thumb);
  179. } else {
  180. $goodsModel->goods_video = '';
  181. $goodsModel->video_image = '';
  182. }
  183. //验证浏览权限
  184. $this->validatePrivilege($goodsModel, $member);
  185. //商品营销 todo 优化新的
  186. $goodsModel->goods_sale = $this->getGoodsSaleV2($goodsModel, $member);
  187. $goodsModel->love_shoppin_gift = $this->loveShoppingGift($goodsModel);
  188. //商品会员优惠
  189. $goodsModel->member_discount = $this->getDiscount($goodsModel, $member);
  190. //商品是否开启领优惠卷
  191. $goodsModel->availability = $this->couponsMemberLj($member);
  192. // 商品详情挂件
  193. if (\app\common\modules\shop\ShopConfig::current()->get('goods_detail')) {
  194. foreach (\app\common\modules\shop\ShopConfig::current()->get('goods_detail') as $key_name => $row) {
  195. $row_res = $row['class']::{$row['function']}($id, true);
  196. if ($row_res) {
  197. $goodsModel->$key_name = $row_res;
  198. //供应商在售商品总数
  199. $class = new $row['class']();
  200. if (method_exists($class, 'getGoodsIdsBySid')) {
  201. $supplier_goods_id = SupplierGoods::getGoodsIdsBySid($goodsModel->supplier->id);
  202. $supplier_goods_count = Goods::select('id')
  203. ->whereIn('id', $supplier_goods_id)
  204. ->where('status', 1)
  205. ->count();
  206. $goodsModel->supplier_goods_count = $supplier_goods_count;
  207. }
  208. }
  209. }
  210. }
  211. if ($goodsModel->hasOneShare) {
  212. $goodsModel->hasOneShare->share_thumb = yz_tomedia($goodsModel->hasOneShare->share_thumb);
  213. }
  214. /*
  215. //设置商品相关插件信息
  216. $this->setGoodsPluginsRelations($goodsModel);
  217. */
  218. //该商品下的推广
  219. $goodsModel->show_push = $goodsModel->hasOneSale ? SaleGoods::getPushGoods($goodsModel->hasOneSale) : [];
  220. //销量等于虚拟销量加真实销量
  221. // $goodsModel->show_sales += $goodsModel->virtual_sales;
  222. $goodsModel->get_comment = $this->getComment($id);
  223. $goodsModel->favorable_rate = $this->favorableRate($id);
  224. return $goodsModel;
  225. }
  226. public function getGoods($request, $integrated = null)
  227. {
  228. app('db')->cacheSelect = true;
  229. $id = intval(\YunShop::request()->id);
  230. if (!$id) {
  231. if (is_null($integrated)) {
  232. return $this->errorJson('请传入正确参数.');
  233. } else {
  234. return show_json(0, '请传入正确参数.');
  235. }
  236. }
  237. $goodsModel = $this->_getGoods($id);
  238. //设置商品相关插件信息
  239. $this->setGoodsPluginsRelations($goodsModel);
  240. //供应商logo转格式
  241. if (!empty($goodsModel->supplier)) {
  242. $goodsModel->supplier->logo = yz_tomedia($goodsModel->supplier->logo);
  243. }
  244. //默认供应商店铺名称
  245. if ($goodsModel->supplier->store_name == 'null') {
  246. $goodsModel->supplier->store_name = $goodsModel->supplier->user_name;
  247. }
  248. //判断该商品是否是视频插件商品
  249. $videoDemand = new VideoDemandCourseGoods();
  250. $goodsModel->is_course = $videoDemand->isCourse($id);
  251. //商城租赁
  252. //TODO 租赁插件是否开启 $lease_switch
  253. $lease_switch = LeaseToyGoods::whetherEnabled();
  254. $this->goods_lease_set($goodsModel, $lease_switch);
  255. //判断是否酒店商品
  256. $goodsModel->is_hotel = $goodsModel->plugin_id == 33 ? 1 : 0;
  257. $goodsModel->is_store = $goodsModel->plugin_id == 32 ? 1 : 0;
  258. if (app('plugins')->isEnabled('label')) {
  259. $goodsModel->label = '';
  260. $pic = Setting::get('plugin.label');
  261. if ($pic['is_label']) {
  262. $goodsModel->label = $pic;
  263. }
  264. }
  265. // $goodsModel->get_comment = $this->getComment($id);
  266. //
  267. // $goodsModel->favorable_rate = $this->favorableRate($id);
  268. //商品服务费
  269. $this->goodsServiceFree($goodsModel);
  270. $this->goodsProductMarket($goodsModel);
  271. //优惠券价
  272. $coupon = \app\common\models\Coupon::uniacid()->where('use_type', 2)->where('get_type', 1)->get();
  273. $goods_coupon = null;
  274. if (\Setting::get('shop.coupon.is_show_coupon')) {
  275. foreach ($coupon as $key => $value) {
  276. if ($value->time_limit == 1) {
  277. if (time() < $value->time_statt || time() > $value->time_end) continue;
  278. }
  279. if (in_array($goodsModel->id, $value['goods_ids']) || $goodsModel->id == $value['goods_ids']) {
  280. if ($value['coupon_method'] == 1) {
  281. $goods_coupon['deduct_price'] = bcsub($goodsModel->price, $value['deduct'], 2); //立减折扣//抵扣金额
  282. $goods_coupon['coupon_method'] = $value['coupon_method'];
  283. $goods_coupon['deduct'] = $value['deduct'];
  284. $goods_coupon['discount'] = $value['discount'];
  285. } else if ($value['coupon_method'] == 2) {
  286. $goods_coupon['deduct_price'] = bcmul($goodsModel->price, $value['discount'] / 10, 2); //打折优惠
  287. $goods_coupon['coupon_method'] = $value['coupon_method'];
  288. $goods_coupon['discount'] = $value['discount'];
  289. $goods_coupon['deduct'] = $value['deduct'];
  290. }
  291. if ($goods_coupon['deduct_price'] < 0) {
  292. $goods_coupon['deduct_price'] = 0;
  293. }
  294. }
  295. }
  296. }
  297. $goodsModel->coupon = $goods_coupon;
  298. if (app('plugins')->isEnabled('team-sales')) {
  299. $goodsModel->team_sales_first = GoodsListService::getFirstDividendDetail($goodsModel);
  300. }
  301. if (is_null($integrated)) {
  302. return $this->successJson('成功', $goodsModel);
  303. } else {
  304. return show_json(1, $goodsModel);
  305. }
  306. }
  307. public function getGoodsPage()
  308. {
  309. if (!miniVersionCompare('1.1.96') || !versionCompare('1.1.096')) {
  310. return $this->oldgetGoodsPage();
  311. }
  312. $goods_id = request()->id;
  313. //查出商品模型
  314. $goods_model = app('GoodsDetail')->make('Goods')->find($goods_id);
  315. if (is_null($goods_model)) {
  316. return $this->errorJson('商品不存在');
  317. }
  318. //实例化所有商品详情类
  319. app('GoodsDetail')->initDetailInstance();
  320. //设置商品详情主类
  321. app('GoodsDetail')->setDetailInstance($goods_model);
  322. //获取商品详情主类
  323. $detail_service = app('GoodsDetail')->make('GoodsDetailInstance');
  324. //初始化数据
  325. $detail_service->init($goods_model);
  326. //获取商品数据
  327. $detail_service->getData();
  328. return $this->successJson('成功', $detail_service->detail_data);
  329. }
  330. public function oldgetGoodsPage()
  331. {
  332. //查询加缓存
  333. app('db')->cacheSelect = true;
  334. $is_new_goods = 0;
  335. if (app('plugins')->isEnabled('decorate') && \Setting::get('plugin.decorate.is_open') == "1") {
  336. //商品模版
  337. $pc_status = 0;
  338. if (!empty(\YunShop::request()->pc) && app('plugins')->isEnabled('pc-terminal')) {
  339. $pc_status = \Yunshop\PcTerminal\service\SetService::getPcStatus(); //PC端开启状态
  340. }
  341. if (!empty($pc_status)) {
  342. $view_set = DecorateTempletModel::getList(['is_default' => 1, 'type' => 6], '*', false);
  343. if ($view_set && $view_set->code == 'PCGoods02') {
  344. $is_new_goods = 1;
  345. }
  346. } else {
  347. $view_set = DecorateTempletModel::getList(['is_default' => 1, 'type' => 4], '*', false);
  348. if ($view_set && $view_set->code == 'goods02') {
  349. $is_new_goods = 1;
  350. }
  351. }
  352. } elseif (app('plugins')->isEnabled('designer')) {
  353. //商品模版
  354. $view_set = ViewSet::uniacid()->where('type', 'goods')->first();
  355. if (!empty($view_set) && $view_set->names == '02') {
  356. $is_new_goods = 1;
  357. }
  358. }
  359. //直播插件
  360. $this->apiData['is_room'] = (integer)(app('plugins')->isEnabled('room') && Setting::get('plugin.room_set_basic')['is_open_room']);
  361. //客服设置
  362. //1.商城客服设置
  363. $shopSet = \Setting::get('shop.shop');
  364. $shop_cservice = $shopSet['cservice'] ?: '';
  365. foreach ((new ServiceController())->index() as $k => $v) {
  366. $this->apiData[$k] = $v;
  367. }
  368. //2.客服插件设置
  369. $alonge_cservice = $this->apiData['cservice'];
  370. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('customer_service'))) {
  371. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('customer_service'), 'class');
  372. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('customer_service'), 'function');
  373. $ret = $class::$function(request()->id, request()->type);
  374. if ($ret) {
  375. if (is_array($ret)) {
  376. foreach ($ret as $rk => $rv) {
  377. $this->apiData[$rk] = $rv;
  378. }
  379. }
  380. }
  381. }
  382. //3.门店单独客服设置
  383. $store_cservice = "";
  384. if (class_exists('\Yunshop\StoreCashier\common\services\CustomerService')) {
  385. $storeSet = CustomerService::getCservice(request()->id, request()->type);
  386. if ($storeSet) {
  387. if (is_array($storeSet)) {
  388. foreach ($storeSet as $sk => $sv) {
  389. $this->apiData[$sk] = $sv;
  390. }
  391. }
  392. //先将门店单独客服设置的cservice取出
  393. if ($storeSet['cservice']) {
  394. $store_cservice = $storeSet['cservice'];
  395. }
  396. }
  397. }
  398. $rg_cservice = "";
  399. if ($is_new_goods == 1) {
  400. $newGoodsController = new NewGoodsController();
  401. $request = request();
  402. $this->dataIntegrated($newGoodsController->getGoods($request, true), 'get_goods');
  403. $this->dataIntegrated($newGoodsController->getGoodsType($request, true), 'goods_type');
  404. $storeId = $this->apiData['get_goods']->store_goods->store_id;
  405. //4.人工客服设置
  406. if ($storeId) {
  407. if (class_exists('\Yunshop\StoreCashier\store\models\StoreService')) {
  408. $storeModel = new \Yunshop\StoreCashier\store\models\StoreService();
  409. $store_service = $storeModel->where("store_id", $storeId)->first();
  410. if ($store_service) {
  411. $rg_cservice = $store_service['service'];
  412. }
  413. }
  414. }
  415. if ($storeId) {
  416. if (class_exists('\Yunshop\StoreCashier\frontend\store\NewGoodsController')) {
  417. if ($this->apiData['goods_type']['store_id']) {
  418. $this->dataIntegrated(\Yunshop\StoreCashier\frontend\store\NewGoodsController::getStoreService($request, true, $this->apiData['goods_type']['store_id']), 'store_service');
  419. }
  420. $this->dataIntegrated(\Yunshop\StoreCashier\frontend\store\NewGoodsController::getInfobyStoreId($request, true, $storeId), 'get_store_Info');
  421. if (MemberService::isLogged()) {
  422. $this->dataIntegrated(\Yunshop\StoreCashier\frontend\shoppingCart\MemberCartController::index($request, true, $storeId), 'member_cart');
  423. }
  424. } else {
  425. return $this->errorJson('门店插件未开启');
  426. }
  427. }
  428. if ($this->apiData['get_goods']->is_hotel) {
  429. if (class_exists('\Yunshop\Hotel\frontend\hotel\NewGoodsController')) {
  430. $this->dataIntegrated(\Yunshop\Hotel\frontend\hotel\NewGoodsController::getGoodsDetailByGoodsId($request, true), 'get_hotel_info');
  431. } else {
  432. return $this->errorJson('酒店插件未开启');
  433. }
  434. }
  435. if (Setting::get('shop.member')['display_page'] == 1 && Setting::get('shop.member')['level_type'] == 2) {
  436. $this->apiData['display_page'] = 1;
  437. } else {
  438. $this->apiData['display_page'] = 0;
  439. }
  440. $this->dataIntegrated($this->pluginEnabled(), 'pluginEnabled');
  441. } else {
  442. $request = request();
  443. $this->dataIntegrated($this->getGoods($request, true), 'get_goods');
  444. $this->dataIntegrated($this->getGoodsType($request, true), 'goods_type');
  445. $storeId = $this->apiData['get_goods']->store_goods->store_id;
  446. //人工客服设置
  447. if ($storeId) {
  448. if (class_exists('\Yunshop\StoreCashier\store\models\StoreService')) {
  449. $storeModel = new \Yunshop\StoreCashier\store\models\StoreService();
  450. $store_service = $storeModel->where("store_id", $storeId)->first();
  451. if ($store_service) {
  452. $rg_cservice = $store_service['service'];
  453. }
  454. }
  455. }
  456. if ($storeId) {
  457. if (class_exists('\Yunshop\StoreCashier\frontend\store\GetStoreInfoController')) {
  458. if ($this->apiData['goods_type']['store_id']) {
  459. $this->dataIntegrated(\Yunshop\StoreCashier\frontend\store\StoreController::getStoreService($request, true, $this->apiData['goods_type']['store_id']), 'store_service');
  460. }
  461. $this->dataIntegrated(\Yunshop\StoreCashier\frontend\store\GetStoreInfoController::getInfobyStoreId($request, true, $storeId), 'get_store_Info');
  462. $this->dataIntegrated(\Yunshop\StoreCashier\frontend\shoppingCart\MemberCartController::index($request, true, $storeId), 'member_cart');
  463. if (!is_null($event_arr = \app\common\modules\shop\ShopConfig::current()->get('form_store_member_cart'))) {
  464. foreach ($event_arr as $v) {
  465. $class = array_get($v, 'class');
  466. $function = array_get($v, 'function');
  467. $this->dataIntegrated($class::$function($this->apiData), 'member_cart');
  468. }
  469. }
  470. } else {
  471. return $this->errorJson('门店插件未开启');
  472. }
  473. // todo 门店预约商品信息
  474. }
  475. if ($this->apiData['get_goods']->is_hotel) {
  476. if (class_exists('\Yunshop\Hotel\frontend\hotel\GoodsController')) {
  477. $this->dataIntegrated(\Yunshop\Hotel\frontend\hotel\GoodsController::getGoodsDetailByGoodsId($request, true), 'get_hotel_info');
  478. } else {
  479. return $this->errorJson('酒店插件未开启');
  480. }
  481. }
  482. if (app('plugins')->isEnabled('guide-page')) {
  483. if (class_exists('\Yunshop\GuidePage\frontend\GuidePageController')) {
  484. $this->dataIntegrated(\Yunshop\GuidePage\frontend\GuidePageController::index(), 'get_guidepage_info');
  485. } else {
  486. return $this->errorJson('引导页插件未开启');
  487. }
  488. }
  489. if (Setting::get('shop.member')['display_page'] == 1 && Setting::get('shop.member')['level_type'] == 2) {
  490. $this->apiData['display_page'] = 1;
  491. } else {
  492. $this->apiData['display_page'] = 0;
  493. }
  494. $this->dataIntegrated(\app\frontend\modules\member\controllers\MemberHistoryController::store($request, true), 'store');
  495. $this->dataIntegrated(\app\frontend\modules\member\controllers\MemberFavoriteController::isFavorite($request, true), 'is_favorite');
  496. $this->dataIntegrated($this->pluginEnabled(), 'pluginEnabled');
  497. }
  498. //满足1.门店独立设置 2.客服插件 3.人工客服 4.商城
  499. if ($store_cservice) {
  500. $this->apiData['cservice'] = $store_cservice;
  501. } else if ($alonge_cservice) {
  502. $this->apiData['cservice'] = $alonge_cservice;
  503. } else if ($rg_cservice) {
  504. $this->apiData['cservice'] = $rg_cservice;
  505. } else {
  506. $this->apiData['cservice'] = $shop_cservice;
  507. }
  508. //自购省
  509. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('selfbuy_discount_show')) && empty($is_new_goods)) {
  510. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('selfbuy_discount_show'), 'class');
  511. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('selfbuy_discount_show'), 'function');
  512. if (empty($this->api_data['get_goods']['member_discount'])) {
  513. $g = $this->_getGoods($request->id, true);
  514. $g = $g ? ['get_goods' => $g->toArray()] : [];
  515. $this->dataIntegrated($class::$function($request, $g), 'selfbuy_discount');
  516. } else {
  517. $this->dataIntegrated($class::$function($request, $this->apiData), 'selfbuy_discount');
  518. }
  519. }
  520. $this->apiData["wechatcircle_open"] = 0;
  521. if (app('plugins')->isEnabled('wechatcircle_products') && Setting::get("plugin.wechatcircle_products")['is_open'] == 1) {
  522. $this->apiData["wechatcircle_open"] = 1;
  523. }
  524. //订单飘窗
  525. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('broadcast_data'))) {
  526. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('broadcast_data'), 'class');
  527. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('broadcast_data'), 'function');
  528. $ret = $class::$function();
  529. if ($ret) {
  530. $this->apiData['broadcast_data'] = $ret;
  531. }
  532. }
  533. //拓客卡
  534. if ($this->apiData['goods_type']['customer_development'] == 1) {
  535. if (app('plugins')->isEnabled('customer-development')) {
  536. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('customer_development_goods'))) {
  537. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('customer_development_goods'), 'class');
  538. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('customer_development_goods'), 'function');
  539. $this->apiData['customer_development'] = $class::$function(request()->id);
  540. }
  541. } else {
  542. return $this->errorJson('拓客卡插件未开启');
  543. }
  544. }
  545. //抽奖数据
  546. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('luck-draw'))) {
  547. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('luck-draw'), 'class');
  548. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('luck-draw'), 'function');
  549. $ret = $class::$function($request->id);
  550. if ($ret) {
  551. $this->apiData['luck_draw'] = $ret;
  552. }
  553. }
  554. return $this->successJson('', $this->apiData);
  555. }
  556. /**
  557. * 判断插件当前是否启用
  558. * @return array
  559. */
  560. protected function pluginEnabled()
  561. {
  562. $data['package_deliver_enabled'] = app('plugins')->isEnabled('package-deliver') ? 1 : 0;
  563. $data['help_center_enabled'] = app('plugins')->isEnabled('help-center') ? 1 : 0;
  564. if (app('plugins')->isEnabled('wx-video-link')) {
  565. $set = WxVideoLikeSetModel::uniacid()->first();
  566. $data['wx_video_link'] = $set['is_open'];
  567. // $data['wx_video_link'] = app('plugins')->isEnabled('wx-video-link')?1:0;
  568. }
  569. return show_json(1, $data);
  570. }
  571. /**
  572. * todo 此方法需要优化,把插件的内容写到插件里面,通过配置文件读取
  573. * todo 插件关闭前端商城就不应该显示关闭插件的商品
  574. * @param $request
  575. * @param null $integrated
  576. * @return array|\Illuminate\Http\JsonResponse
  577. */
  578. public function getGoodsType($request, $integrated = null)
  579. {
  580. app('db')->cacheSelect = true;
  581. $goods_type = 'goods';//通用
  582. $id = request()->id;
  583. if (!$id) {
  584. if (is_null($integrated)) {
  585. return $this->errorJson('请传入正确参数.');
  586. } else {
  587. return show_json(0, '请传入正确参数.');
  588. }
  589. }
  590. $goodsModel = Goods::uniacid()->find($id);
  591. $data['title'] = $goodsModel->title;
  592. // 商品详情挂件
  593. if (\app\common\modules\shop\ShopConfig::current()->get('goods_detail')) {
  594. foreach (\app\common\modules\shop\ShopConfig::current()->get('goods_detail') as $key_name => $row) {
  595. $row_res = $row['class']::{$row['function']}($id, true);
  596. if ($row_res) {
  597. $goodsModel->$key_name = $row_res;
  598. }
  599. }
  600. }
  601. //判断该商品是否是视频插件商品
  602. $isCourse = (new VideoDemandCourseGoods())->isCourse($id);
  603. if ($isCourse) {
  604. $goods_type = 'course';
  605. }
  606. //判断是否酒店商品
  607. if ($goodsModel->plugin_id == 33) {
  608. $goods_type = 'hotelGoods';
  609. }
  610. if ($goodsModel->plugin_id == 66) {
  611. $goods_type = 'voiceGoods';
  612. }
  613. //门店商品
  614. if ($goodsModel->plugin_id == 32 && $goodsModel->store_goods) {
  615. $goods_type = 'store_goods';
  616. $store_id = $goodsModel->store_goods->store_id;
  617. $data['store_id'] = $store_id;
  618. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('customer_development_judge'))) {
  619. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('customer_development_judge'), 'class');
  620. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('customer_development_judge'), 'function');
  621. $judge_res = $class::$function($goodsModel->id);
  622. if ($judge_res == 1) {
  623. $data['customer_development'] = 1;
  624. }
  625. }
  626. }
  627. //供应商商品
  628. if ($goodsModel->plugin_id == 92 && $goodsModel->supplier) {
  629. $goods_type = 'supplierGoods';
  630. }
  631. //分期购车插件
  632. if ($goodsModel->plugin_id == 47) {
  633. $goods_type = 'staging_buy_car_goods';
  634. }
  635. //预约插件
  636. if ($goodsModel->plugin_id == 101) {
  637. $goods_type = 'appointment_goods';
  638. }
  639. //芸签电子合同插件
  640. if ($goodsModel->plugin_id == 103) {
  641. $goods_type = 'yun_sign_goods';
  642. }
  643. $data['goods_type'] = $goods_type;
  644. if (is_null($integrated)) {
  645. return $this->successJson('成功', $data);
  646. } else {
  647. return show_json(1, $data);
  648. }
  649. }
  650. /**
  651. * @param $goodsModel
  652. * @param $member
  653. * @throws \app\common\exceptions\AppException
  654. */
  655. public function validatePrivilege($goodsModel, $member)
  656. {
  657. Privilege::validatePrivilegeLevel($goodsModel, $member);
  658. Privilege::validatePrivilegeGroup($goodsModel, $member);
  659. }
  660. private function setGoodsPluginsRelations($goods)
  661. {
  662. $goodsRelations = app('GoodsManager')->tagged('GoodsRelations');
  663. collect($goodsRelations)->each(function ($goodsRelation) use ($goods) {
  664. $goodsRelation->setGoods($goods);
  665. });
  666. }
  667. public function searchGoods()
  668. {
  669. app('db')->cacheSelect = true;
  670. $requestSearch = \YunShop::request()->search;
  671. $order_field = \YunShop::request()->order_field;
  672. $goods_model = \app\common\modules\shop\ShopConfig::current()->get('goods.models.commodity_classification');
  673. $goods_model = new $goods_model;
  674. if (!in_array($order_field, ['price', 'show_sales', 'comment_num'])) {
  675. $order_field = 'display_order';
  676. } else {
  677. if ($order_field == 'show_sales') {
  678. //排序改为虚拟销量
  679. $order_field = 'total_sales';
  680. }
  681. }
  682. $order_by = (\YunShop::request()->order_by == 'asc') ? 'asc' : 'desc';
  683. if ($requestSearch) {
  684. $requestSearch = array_filter($requestSearch, function ($item) {
  685. return !empty($item) && $item !== 0 && $item !== "undefined";
  686. });
  687. $categorySearch = array_filter(\YunShop::request()->category, function ($item) {
  688. return !empty($item);
  689. });
  690. if ($categorySearch) {
  691. $requestSearch['category'] = $categorySearch;
  692. }
  693. }
  694. $build = $goods_model->Search($requestSearch)->selectRaw("thumb,real_sales+virtual_sales total_sales,market_price,price,cost_price,title, " . DB::getTablePrefix() . "yz_goods.id as goods_id")
  695. ->where("yz_goods.status", 1)
  696. ->whereInPluginIds();
  697. //todo 为什么要取出id, 这样mysql where in的好长
  698. /*$id_arr = collect($list->get())->map(function ($rows) {
  699. return $rows['id'];
  700. });*/
  701. $list = $build->orderBy($order_field, $order_by)
  702. ->orderBy('yz_goods.id', 'desc')
  703. ->paginate(20);
  704. if ($list->isEmpty()) {
  705. return $this->errorJson('没有找到商品.');
  706. }
  707. //TODO 租赁插件是否开启 $lease_switch
  708. $lease_switch = LeaseToyGoods::whetherEnabled();
  709. //由于之前 foreach 太多了 合在一起
  710. $list->map(function ($item) use ($lease_switch) {
  711. $item->thumb = yz_tomedia($item->thumb);
  712. //租赁商品
  713. $this->goods_lease_set($item, $lease_switch);
  714. $item->id = $item->goods_id;
  715. //会员vip价格
  716. $item->vip_price = $item->vip_price;
  717. $item->vip_next_price = $item->vip_next_price;
  718. $item->vip_level_status = $item->vip_level_status;
  719. $item->price_level = $item->price_level;
  720. $item->is_open_micro = $item->is_open_micro;
  721. return $item;
  722. });
  723. $list = $list->toArray();
  724. $category_data = [
  725. 'names' => '01',
  726. 'type' => 'goodsList',
  727. ];
  728. if (app('plugins')->isEnabled('decorate') && \Setting::get('plugin.decorate.is_open') == 1) {
  729. // $view_set = \Yunshop\Decorate\models\DecorateTempletModel::uniacid()
  730. // ->where('code','goodsList02')
  731. // ->where('type',5)
  732. // ->where('is_default',1)
  733. // ->first();
  734. // $category_data = $view_set ? ['names' => '02', 'type' => 'goodsList']: $category_data;
  735. $view_set = \Yunshop\Decorate\models\DecorateTempletModel::uniacid()
  736. ->whereIn('code', ['goodsList01', 'goodsList02', 'goodsList03'])
  737. ->where('type', 5)
  738. ->where('is_default', 1)
  739. ->first();
  740. $tmp = [
  741. 'goodsList01' => '01',
  742. 'goodsList02' => '02',
  743. 'goodsList03' => '03',
  744. ];
  745. $category_data = $view_set ? ['names' => $tmp[$view_set->code], 'type' => 'goodsList'] : $category_data;
  746. if ($view_set) {
  747. $list['data'] = $this->getGoodsCouponSale($list['data']);
  748. //团队销售佣金一级分销
  749. if (app('plugins')->isEnabled('team-sales')) {
  750. $list['data'] = GoodsListService::getFirstDividend($list['data']);
  751. }
  752. }
  753. if ($category_data['names'] == '03') {
  754. if (app('plugins')->isEnabled('love')) {//爱心值天天兑价
  755. $list['data'] = \Yunshop\Love\Frontend\Models\GoodsLove::setGoodsLove($list['data']);
  756. }
  757. }
  758. } elseif (app('plugins')->isEnabled('designer')) {
  759. //商品分类模板
  760. // $view_set = ViewSet::uniacid()->where('type', 'goodsList')->first();
  761. $view_set = ViewSet::uniacid()->where('type', 'goodsList')->select('names', 'type')->first();
  762. $category_data = $view_set ?: $category_data;
  763. if (!empty($view_set) && $view_set->names == '02') {
  764. $list['data'] = $this->getGoodsCouponSale($list['data']);
  765. //团队销售佣金一级分销
  766. if (app('plugins')->isEnabled('team-sales')) {
  767. $list['data'] = GoodsListService::getFirstDividend($list['data']);
  768. }
  769. }
  770. }
  771. //增加商品链接
  772. if (app('plugins')->isEnabled('goods-link')) {
  773. $list['data'] = GetGoodsDocService::getDoc($list['data']);
  774. }
  775. //积分商城
  776. if (app('plugins')->isEnabled('point-mall')) {
  777. $list['data'] = \Yunshop\PointMall\api\models\PointMallGoodsModel::setPointGoods($list['data']);
  778. }
  779. $list['goods_template'] = $category_data;
  780. return $this->successJson('成功', $list);
  781. }
  782. private function getGoodsCouponSale($goods)
  783. {
  784. //$memberLevel = MemberShopInfo::where('member_id', \YunShop::app()->getMemberId())->with(['level'])->first(); 去除优惠券等级限制
  785. $coupon = \app\common\models\Coupon::uniacid()->where('use_type', 2)->where('get_type', 1)->get();
  786. foreach ($goods as $k => &$v) {
  787. $v['coupon']['coupon_method'] = 0; //商品没有折扣
  788. foreach ($coupon as $key => $value) {
  789. if ($value->time_limit == 1) {
  790. if (time() < $value->time_statt || time() > $value->time_end) continue;
  791. }
  792. if (in_array($v['goods_id'], $value['goods_ids']) || $v['goods_id'] == $value['goods_ids']) {
  793. if ($value['coupon_method'] == 1) {
  794. $v['coupon']['deduct_price'] = bcsub($v['price'], $value['deduct'], 2); //立减折扣
  795. $v['coupon']['coupon_method'] = $value['coupon_method'];
  796. $v['coupon']['deduct'] = $value['deduct'];
  797. $v['coupon']['discount'] = $value['discount'];
  798. } else if ($value['coupon_method'] == 2) {
  799. $v['coupon']['deduct_price'] = bcmul($v['price'], $value['discount'] / 10, 2); //打折优惠
  800. $v['coupon']['coupon_method'] = $value['coupon_method'];
  801. $v['coupon']['discount'] = $value['discount'];
  802. $v['coupon']['deduct'] = $value['deduct'];
  803. }
  804. if ($v['coupon']['deduct_price'] < 0) {
  805. $v['coupon']['deduct_price'] = 0;
  806. }
  807. if ($v['coupon']['enough'] > 0 && $v['price'] < $value['enough']) {
  808. $v['coupon']['deduct_price'] = 0;
  809. }
  810. }
  811. }
  812. }
  813. return $goods;
  814. }
  815. public function getGoodsCategoryList()
  816. {
  817. $category_id = intval(\YunShop::request()->category_id);
  818. if (empty($category_id)) {
  819. return $this->errorJson('请输入正确的商品分类.');
  820. }
  821. $order_field = \YunShop::request()->order_field;
  822. if (!in_array($order_field, ['price', 'show_sales', 'comment_num'])) {
  823. $order_field = 'display_order';
  824. }
  825. $order_by = (\YunShop::request()->order_by == 'asc') ? 'asc' : 'desc';
  826. $categorys = Category::uniacid()->select("name", "thumb", "id")->where(['id' => $category_id])->first();
  827. if ($categorys) {
  828. $categorys->thumb = yz_tomedia($categorys->thumb);
  829. }
  830. $goodsList = Goods::uniacid()->select('yz_goods.id', 'yz_goods.id as goods_id', 'title', 'thumb', 'price', 'market_price')
  831. ->join('yz_goods_category', 'yz_goods_category.goods_id', '=', 'yz_goods.id')
  832. ->where("category_id", $category_id)
  833. ->where('status', '1')
  834. ->orderBy($order_field, $order_by)
  835. ->paginate(20)->toArray();
  836. if (empty($goodsList)) {
  837. return $this->errorJson('此分类下没有商品.');
  838. }
  839. $goodsList['data'] = set_medias($goodsList['data'], 'thumb');
  840. $categorys->goods = $goodsList;
  841. return $this->successJson('成功', $categorys);
  842. }
  843. public function getGoodsBrandList()
  844. {
  845. $goods_model = \app\common\modules\shop\ShopConfig::current()->get('goods.models.commodity_classification');
  846. $goods_model = new $goods_model;
  847. $brand_id = intval(\YunShop::request()->brand_id);
  848. $order_field = \YunShop::request()->order_field;
  849. if (!in_array($order_field, ['price', 'show_sales', 'comment_num'])) {
  850. $order_field = 'display_order';
  851. }
  852. $order_by = (\YunShop::request()->order_by == 'asc') ? 'asc' : 'desc';
  853. if (empty($brand_id)) {
  854. return $this->errorJson('请输入正确的品牌id.');
  855. }
  856. $brand = Brand::uniacid()->select("name", "logo", "id")->where(['id' => $brand_id])->first();
  857. if (!$brand) {
  858. return $this->errorJson('没有此品牌.');
  859. }
  860. $brand->logo = yz_tomedia($brand->logo);
  861. $goodsList = $goods_model->uniacid()->select('id', 'id as goods_id', 'title', 'thumb', 'price', 'market_price')
  862. ->where('status', '1')
  863. ->where('brand_id', $brand_id)
  864. ->whereInPluginIds()
  865. ->orderBy($order_field, $order_by)
  866. ->paginate(20)->toArray();
  867. $goodsList->vip_level_status;
  868. if (empty($goodsList)) {
  869. return $this->errorJson('此品牌下没有商品.');
  870. }
  871. $goodsList['data'] = set_medias($goodsList['data'], 'thumb');
  872. $category_data = [
  873. 'names' => '01',
  874. 'type' => 'goodsList',
  875. ];
  876. if (app('plugins')->isEnabled('decorate') && \Setting::get('plugin.decorate.is_open') == 1) {
  877. // $view_set = \Yunshop\Decorate\models\DecorateTempletModel::uniacid()
  878. // ->where('code', 'goodsList02')
  879. // ->where('type', 5)
  880. // ->where('is_default', 1)
  881. // ->first();
  882. // $category_data = $view_set ? ['names' => '02', 'type' => 'goodsList'] : $category_data;
  883. //
  884. $view_set = \Yunshop\Decorate\models\DecorateTempletModel::uniacid()
  885. ->whereIn('code', ['goodsList01', 'goodsList02', 'goodsList03'])
  886. ->where('type', 5)
  887. ->where('is_default', 1)
  888. ->first();
  889. $tmp = [
  890. 'goodsList01' => '01',
  891. 'goodsList02' => '02',
  892. 'goodsList03' => '03',
  893. ];
  894. $category_data = $view_set ? ['names' => $tmp[$view_set->code], 'type' => 'goodsList'] : $category_data;
  895. if ($view_set) {
  896. $goodsList['data'] = $this->getGoodsCouponSale($goodsList['data']);
  897. //团队销售佣金一级分销
  898. if (app('plugins')->isEnabled('team-sales')) {
  899. $goodsList['data'] = GoodsListService::getFirstDividend($goodsList['data']);
  900. }
  901. }
  902. if ($category_data['names'] == '03') {
  903. if (app('plugins')->isEnabled('love')) {//爱心值天天兑价
  904. $goodsList['data'] = \Yunshop\Love\Frontend\Models\GoodsLove::setGoodsLove($goodsList['data']);
  905. }
  906. }
  907. } elseif (app('plugins')->isEnabled('designer')) {
  908. //商品分类模板
  909. // $view_set = ViewSet::uniacid()->where('type', 'goodsList')->first();
  910. $view_set = ViewSet::uniacid()->where('type', 'goodsList')->select('names', 'type')->first();
  911. $category_data = $view_set ?: $category_data;
  912. if (!empty($view_set) && $view_set->names == '02') {
  913. $goodsList['data'] = $this->getGoodsCouponSale($goodsList['data']);
  914. //团队销售佣金一级分销
  915. if (app('plugins')->isEnabled('team-sales')) {
  916. $goodsList['data'] = GoodsListService::getFirstDividend($goodsList['data']);
  917. }
  918. }
  919. }
  920. //增加商品链接
  921. if (app('plugins')->isEnabled('goods-link')) {
  922. $goodsList['data'] = GetGoodsDocService::getDoc($goodsList['data']);
  923. }
  924. //积分商城
  925. if (app('plugins')->isEnabled('point-mall')) {
  926. $goodsList['data'] = \Yunshop\PointMall\api\models\PointMallGoodsModel::setPointGoods($goodsList['data']);
  927. }
  928. $goodsList['goods_template'] = $category_data;
  929. $brand->goods = $goodsList;
  930. return $this->successJson('成功', $brand);
  931. }
  932. public function getRecommendGoods()
  933. {
  934. $list = Goods::uniacid()
  935. ->select('id', 'id as goods_id', 'title', 'thumb', 'price', 'market_price')
  936. ->where('is_recommand', '1')
  937. ->whereStatus('1')
  938. ->orderBy('id', 'desc')
  939. ->get();
  940. if (!$list->isEmpty()) {
  941. $list = set_medias($list->toArray(), 'thumb');
  942. }
  943. return $this->successJson('获取推荐商品成功', $list);
  944. }
  945. /**
  946. * 会员折扣后的价格
  947. * @param Goods $goodsModel
  948. * @param [type] $discountModel [description]
  949. * @return array [type] [description]
  950. */
  951. public function getDiscount($goodsModel, $memberModel)
  952. {
  953. if ($goodsModel->vip_price === null) {
  954. return [];
  955. }
  956. $discount_switch = Setting::get('shop.member.discount');
  957. $level_type = Setting::get('shop.member.level_type');
  958. $display_page = Setting::get('shop.member.display_page');
  959. if ($memberModel->level) {
  960. $data = [
  961. 'level_name' => $memberModel->level->level_name,
  962. 'discount_value' => $goodsModel->vip_price,
  963. 'discount' => $discount_switch,
  964. 'next_level_price' => $goodsModel->next_level_price,
  965. 'next_level_name' => $goodsModel->next_level_name,
  966. 'level_type' => $level_type,
  967. 'display_page' => $display_page
  968. ];
  969. } else {
  970. $level = Setting::get('shop.member.level_name');
  971. $level_name = $level ?: '普通会员';
  972. $data = [
  973. 'level_name' => $level_name,
  974. 'discount_value' => $goodsModel->vip_price,
  975. 'discount' => $discount_switch,
  976. 'next_level_price' => $goodsModel->next_level_price,
  977. 'next_level_name' => $goodsModel->next_level_name ?: MemberLevel::value('level_name'),
  978. 'level_type' => $level_type,
  979. 'display_page' => $display_page
  980. ];
  981. }
  982. return $data;
  983. }
  984. public function getGoodsSaleV2($goodsModel, $member)
  985. {
  986. $sale = [];
  987. //商城积分设置
  988. $set = \Setting::get('point.set');
  989. //获取商城设置: 判断 积分、余额 是否有自定义名称
  990. $shopSet = \Setting::get('shop.shop');
  991. if ($goodsModel->hasOneSale->ed_num || $goodsModel->hasOneSale->ed_money) {
  992. $data['name'] = '包邮';
  993. $data['key'] = 'ed_num';
  994. $data['type'] = 'array';
  995. if ($goodsModel->hasOneSale->ed_num) {
  996. $data['value'][] = '本商品满' . $goodsModel->hasOneSale->ed_num . '件包邮';
  997. }
  998. if ($goodsModel->hasOneSale->ed_money) {
  999. $data['value'][] = '本商品满¥' . $goodsModel->hasOneSale->ed_money . '包邮';
  1000. }
  1001. array_push($sale, $data);
  1002. $data = [];
  1003. }
  1004. if ($goodsModel->hasOneSale->all_point_deduct && $goodsModel->hasOneSale->has_all_point_deduct) {//商品设置
  1005. $data['name'] = $shopSet['credit1'] ? $shopSet['credit1'] . '全额抵扣' : '积分全额抵扣';
  1006. $data['key'] = 'all_point_deduct';
  1007. $data['type'] = 'string';
  1008. $data['value'] = '可使用' . $goodsModel->hasOneSale->all_point_deduct . '个' . ($shopSet['credit1'] ? $shopSet['credit1'] . '全额抵扣购买' : '积分全额抵扣购买');
  1009. array_push($sale, $data);
  1010. $data = [];
  1011. }
  1012. if ((bccomp($goodsModel->hasOneSale->ed_full, 0.00, 2) == 1) && (bccomp($goodsModel->hasOneSale->ed_reduction, 0.00, 2) == 1)) {
  1013. $data['name'] = '满减';
  1014. $data['key'] = 'ed_full';
  1015. $data['type'] = 'string';
  1016. $data['value'] = '本商品满¥' . $goodsModel->hasOneSale->ed_full . '立减¥' . $goodsModel->hasOneSale->ed_reduction;
  1017. array_push($sale, $data);
  1018. $data = [];
  1019. }
  1020. if ($goodsModel->hasOneSale->award_balance) {
  1021. $data['name'] = $shopSet['credit'] ?: '余额';
  1022. $data['key'] = 'award_balance';
  1023. $data['type'] = 'string';
  1024. $data['value'] = '购买赠送' . $goodsModel->hasOneSale->award_balance . $data['name'];
  1025. array_push($sale, $data);
  1026. $data = [];
  1027. }
  1028. $point = [];
  1029. if (app('plugins')->isEnabled('store-cashier')) {//门店抵扣设置
  1030. $store_goods = StoreGoods::where('goods_id', $goodsModel->id)->first();
  1031. $point = StoreSetting::getStoreSettingByStoreId($store_goods->store_id)->where('key', 'point')->first();
  1032. }
  1033. $data['name'] = $shopSet['credit1'] ?: '积分';
  1034. $data['key'] = 'point';
  1035. $data['type'] = 'array';
  1036. if ((strlen($goodsModel->hasOneSale->point) === 0) || $goodsModel->hasOneSale->point != 0) {
  1037. if ($goodsModel->hasOneSale->point) {
  1038. $points = $goodsModel->hasOneSale->point;
  1039. } elseif (!empty($point['value']['set']['give_point']) && $point['value']['set']['give_point'] != 0) {//门店抵扣设置
  1040. $points = $point['value']['set']['give_point'] . '%';
  1041. } else {
  1042. $points = $set['give_point'] ? $set['give_point'] : 0;
  1043. }
  1044. if (!empty($points)) {
  1045. $data['value'][] = '购买赠送' . $points . $data['name'];
  1046. }
  1047. }
  1048. //设置不等于0,支持积分抵扣
  1049. //积分抵扣优先级 商品独立设置 ---> 门店设置 ---> 积分统一设置
  1050. if ($set['point_deduct'] && (strlen($goodsModel->hasOneSale->max_point_deduct) === 0 || $goodsModel->hasOneSale->max_point_deduct != 0)) {
  1051. if ($goodsModel->hasOneSale->max_point_deduct) {
  1052. $max_point_deduct = $goodsModel->hasOneSale->max_point_deduct . '元';
  1053. } elseif (strlen($point['value']['set']['money_max']) !== 0) {
  1054. if (!($point['value']['set']['money_max'] === 0 || $point['value']['set']['money_max'] === '0')) {
  1055. $max_point_deduct = $point['value']['set']['money_max'] . '%';
  1056. }
  1057. } else {
  1058. $max_point_deduct = $set['money_max'] ? $set['money_max'] . '%' : 0;
  1059. }
  1060. if (!empty(mb_substr($max_point_deduct, 0, -1))) {
  1061. $data['value'][] = '最高抵扣' . $max_point_deduct;
  1062. }
  1063. }
  1064. if ($set['point_deduct'] && (strlen($goodsModel->hasOneSale->min_point_deduct) === 0 || $goodsModel->hasOneSale->min_point_deduct != 0)) {
  1065. if ($goodsModel->hasOneSale->min_point_deduct) {
  1066. $min_point_deduct = $goodsModel->hasOneSale->min_point_deduct . '元';
  1067. } else {
  1068. $min_point_deduct = $set['money_min'] ? $set['money_min'] . '%' : 0;
  1069. }
  1070. if (!empty(mb_substr($min_point_deduct, 0, -1))) {
  1071. $data['value'][] = '最少抵扣' . $min_point_deduct;
  1072. }
  1073. }
  1074. if (!empty($data['value'])) {
  1075. array_push($sale, $data);
  1076. }
  1077. $data = [];
  1078. if ($goodsModel->hasOneGoodsCoupon->is_give) {
  1079. $data['name'] = '购买返券';
  1080. $data['key'] = 'coupon';
  1081. $data['type'] = 'string';
  1082. $data['value'] = $goodsModel->hasOneGoodsCoupon->send_type ? '商品订单完成返优惠券' : '每月一号返优惠券';
  1083. array_push($sale, $data);
  1084. $data = [];
  1085. }
  1086. //爱心值
  1087. $exist_love = app('plugins')->isEnabled('love');
  1088. if ($exist_love) {
  1089. $love_goods = $this->getLoveSet($goodsModel, $goodsModel->id);
  1090. $data['name'] = $love_goods['name'];
  1091. $data['key'] = 'love';
  1092. $data['type'] = 'array';
  1093. if ($love_goods['deduction']) {
  1094. $data['value'][] = '最高抵扣' . $love_goods['deduction_proportion'] . $data['name'];
  1095. }
  1096. if ($love_goods['award'] && \Setting::get('love.goods_detail_show_love') != 2) {
  1097. $data['value'][] = '购买赠送' . $love_goods['award_proportion'] . $data['name'];
  1098. }
  1099. if (!empty($data['value'])) {
  1100. array_push($sale, $data);
  1101. }
  1102. $data = [];
  1103. }
  1104. //佣金
  1105. $exist_commission = app('plugins')->isEnabled('commission');
  1106. if ($exist_commission) {
  1107. $is_agent = $this->isValidateCommission($member);
  1108. if ($is_agent) {
  1109. $commission_data = (new GoodsDetailService($goodsModel))->getGoodsDetailData();
  1110. if ($commission_data['commission_show'] == 1) {
  1111. // $data['name'] = '佣金';
  1112. $data['key'] = 'commission';
  1113. $data['type'] = 'array';
  1114. $lang = isset($lang) ? $lang : \Setting::get('shop.lang');
  1115. $commission_alisa = array_get($lang, 'zh_cn.commission.commission_alias', '佣金') ?: '佣金';
  1116. $data['name'] = $commission_alisa;
  1117. $data['desc'] = '最终获得' . $commission_alisa . '根据等级、独立' . $commission_alisa . '设置、下单实际支付金额等因数决定,请以最终到账' . $commission_alisa . '为准!';
  1118. if (!empty($commission_data['first_commission']) && ($commission_data['commission_show_level'] > 0)) {
  1119. // $data['value'][] = '一级佣金' . $commission_data['first_commission'] . '元';
  1120. $data['value'][] = '一级' . $commission_alisa . $commission_data['first_commission'] . '元';
  1121. }
  1122. if (!empty($commission_data['second_commission']) && ($commission_data['commission_show_level'] > 1)) {
  1123. // $data['value'][] = '二级佣金' . $commission_data['second_commission'] . '元';
  1124. $data['value'][] = '二级' . $commission_alisa . $commission_data['second_commission'] . '元';
  1125. }
  1126. if (!empty($commission_data['third_commission']) && ($commission_data['commission_show_level'] > 2)) {
  1127. // $data['value'][] = '三级佣金' . $commission_data['third_commission'] . '元';
  1128. $data['value'][] = '三级' . $commission_alisa . $commission_data['third_commission'] . '元';
  1129. }
  1130. array_push($sale, $data);
  1131. $data = [];
  1132. }
  1133. }
  1134. }
  1135. //经销商提成
  1136. $exist_team_dividend = app('plugins')->isEnabled('team-dividend');
  1137. if ($exist_team_dividend) {
  1138. //验证是否是经销商及等级
  1139. $is_agent = $this->isValidateTeamDividend($member);
  1140. if ($is_agent) {
  1141. // $lang = \Setting::get('shop.lang');
  1142. $lang = isset($lang) ? $lang : \Setting::get('shop.lang');
  1143. $team_dividend_name = array_get($lang, 'zh_cn.team_dividend.title', '经销商') ?: '经销商';
  1144. $dividend_alisa = array_get($lang, 'zh_cn.team_dividend.dividend_alias', $team_dividend_name . '提成') ?: $team_dividend_name . '提成';
  1145. //返回经销商等级奖励比例 商品等级奖励规则
  1146. $team_dividend_data = (new TeamDividendGoodsDetailService($goodsModel))->getGoodsDetailData();
  1147. if ($team_dividend_data['team_dividend_show'] == 1) {
  1148. // $data['name'] = $team_dividend_name.'提成';
  1149. $data['name'] = $dividend_alisa;
  1150. $data['key'] = 'team-dividend';
  1151. $data['type'] = 'array';
  1152. // $data['value'][] = $team_dividend_name.'提成' . $team_dividend_data['team_dividend_royalty'];
  1153. $data['value'][] = $dividend_alisa . $team_dividend_data['team_dividend_royalty'];
  1154. array_unshift($sale, $data);
  1155. $data = [];
  1156. }
  1157. }
  1158. }
  1159. $exist_pending_order = app('plugins')->isEnabled('pending-order');
  1160. if ($exist_pending_order) {
  1161. $pending_order_goods = \Yunshop\PendingOrder\services\PendingOrderGoodsService::getGoodsWholesaleSend($goodsModel->id);
  1162. $pending_order['name'] = '批发劵';
  1163. $pending_order['key'] = 'pending-order';
  1164. $pending_order['type'] = 'array';
  1165. if ($pending_order_goods['send_condition']['code']) {
  1166. $pending_order['value'][] = $pending_order_goods['send_condition']['msg'];
  1167. array_push($sale, $pending_order);
  1168. }
  1169. }
  1170. return [
  1171. 'sale_count' => count($sale),
  1172. // 'first_strip_key' => $sale ? $sale[rand(0, (count($sale) - 1))] : [],
  1173. 'first_strip_key' => $sale[0] ? $sale[0] : [],
  1174. 'sale' => $sale,
  1175. ];
  1176. }
  1177. public function isValidateCommission($member)
  1178. {
  1179. return Agents::getAgentByMemberId($member->member_id)->first();
  1180. }
  1181. public function isValidateTeamDividend($member)
  1182. {
  1183. return TeamDividendAgencyModel::getAgencyByMemberId($member->member_id)->first();
  1184. }
  1185. /**
  1186. * 商品的营销
  1187. * @param [type] $goodsModel [description]
  1188. * @return [type] [description]
  1189. */
  1190. public function getGoodsSale($goodsModel)
  1191. {
  1192. $set = \Setting::get('point.set');
  1193. $shopSet = \Setting::get('shop.shop');
  1194. if (!empty($shopSet['credit1'])) {
  1195. $point_name = $shopSet['credit1'];
  1196. } else {
  1197. $point_name = '积分';
  1198. }
  1199. $data = [
  1200. 'first_strip_key' => 0,
  1201. 'point_name' => $point_name, //积分名称
  1202. 'love_name' => '爱心值',
  1203. 'ed_num' => 0, //满件包邮
  1204. 'ed_money' => 0, //满额包邮
  1205. 'ed_full' => 0, //单品满额
  1206. 'ed_reduction' => 0, //单品立减
  1207. 'award_balance' => 0, //赠送余额
  1208. 'point' => 0, //赠送积分
  1209. 'max_point_deduct' => 0, //积分最大抵扣
  1210. 'min_point_deduct' => 0, //积分最小抵扣
  1211. 'coupon' => 0, //商品优惠券赠送
  1212. 'deduction_proportion' => 0, //爱心值最高抵扣
  1213. 'award_proportion' => 0, //奖励爱心值
  1214. 'sale_count' => 0, //活动总数
  1215. ];
  1216. if (ceil($goodsModel->hasOneSale->ed_full) && ceil($goodsModel->hasOneSale->ed_reduction)) {
  1217. $data['ed_full'] = $goodsModel->hasOneSale->ed_full;
  1218. $data['ed_reduction'] = $goodsModel->hasOneSale->ed_reduction;
  1219. $data['first_strip_key'] = 'ed_full';
  1220. $data['sale_count'] += 1;
  1221. }
  1222. if ($goodsModel->hasOneSale->award_balance) {
  1223. $data['award_balance'] = $goodsModel->hasOneSale->award_balance;
  1224. $data['first_strip_key'] = 'award_balance';
  1225. $data['sale_count'] += 1;
  1226. }
  1227. if ($goodsModel->hasOneSale->point !== '0') {
  1228. $data['point'] = $set['give_point'] ? $set['give_point'] : 0;
  1229. if ($goodsModel->hasOneSale->point) {
  1230. $data['point'] = $goodsModel->hasOneSale->point;
  1231. }
  1232. if (!empty($data['point'])) {
  1233. $data['first_strip_key'] = 'point';
  1234. $data['sale_count'] += 1;
  1235. }
  1236. }
  1237. if ($set['point_deduct'] && $goodsModel->hasOneSale->max_point_deduct !== '0') {
  1238. $data['max_point_deduct'] = $set['money_max'] ? $set['money_max'] . '%' : 0;
  1239. if ($goodsModel->hasOneSale->max_point_deduct) {
  1240. $data['max_point_deduct'] = $goodsModel->hasOneSale->max_point_deduct;
  1241. }
  1242. if (!empty($data['max_point_deduct'])) {
  1243. $data['first_strip_key'] = 'max_point_deduct';
  1244. $data['sale_count'] += 1;
  1245. }
  1246. }
  1247. if ($set['point_deduct'] && $goodsModel->hasOneSale->min_point_deduct !== '0') {
  1248. $data['min_point_deduct'] = $set['money_min'] ? $set['money_min'] . '%' : 0;
  1249. if ($goodsModel->hasOneSale->min_point_deduct) {
  1250. $data['min_point_deduct'] = $goodsModel->hasOneSale->min_point_deduct;
  1251. }
  1252. if (!empty($data['min_point_deduct'])) {
  1253. $data['first_strip_key'] = 'min_point_deduct';
  1254. $data['sale_count'] += 1;
  1255. }
  1256. }
  1257. if ($goodsModel->hasOneGoodsCoupon->is_give) {
  1258. $data['coupon'] = $goodsModel->hasOneGoodsCoupon->send_type ? '商品订单完成返优惠券' : '每月一号返优惠券';
  1259. $data['first_strip_key'] = 'coupon';
  1260. $data['sale_count'] += 1;
  1261. }
  1262. if ($goodsModel->hasOneSale->ed_num) {
  1263. $data['ed_num'] = $goodsModel->hasOneSale->ed_num;
  1264. $data['first_strip_key'] = 'ed_num';
  1265. $data['sale_count'] += 1;
  1266. }
  1267. if ($goodsModel->hasOneSale->ed_money) {
  1268. $data['ed_money'] = $goodsModel->hasOneSale->ed_money;
  1269. $data['first_strip_key'] = 'ed_money';
  1270. $data['sale_count'] += 1;
  1271. }
  1272. $exist_love = app('plugins')->isEnabled('love');
  1273. if ($exist_love) {
  1274. $love_goods = $this->getLoveSet($goodsModel, $goodsModel->id);
  1275. $data['love_name'] = $love_goods['name'];
  1276. if ($love_goods['deduction']) {
  1277. $data['deduction_proportion'] = $love_goods['deduction_proportion'];
  1278. $data['first_strip_key'] = 'deduction_proportion';
  1279. $data['sale_count'] += 1;
  1280. }
  1281. if ($love_goods['award']) {
  1282. $data['award_proportion'] = $love_goods['award_proportion'];
  1283. $data['first_strip_key'] = 'award_proportion';
  1284. $data['sale_count'] += 1;
  1285. }
  1286. }
  1287. $exist_commission = app('plugins')->isEnabled('commission');
  1288. if ($exist_commission) {
  1289. $commission_data = (new GoodsDetailService($goodsModel))->getGoodsDetailData();
  1290. if ($commission_data['commission_show'] == 1) {
  1291. $data['sale_count'] += 1;
  1292. $data['first_strip_key'] = 'commission_show';
  1293. }
  1294. $data = array_merge($data, $commission_data);
  1295. }
  1296. return $data;
  1297. }
  1298. /**
  1299. * 获取商品爱心值设置
  1300. */
  1301. public function getLoveSet($goods, $goods_id)
  1302. {
  1303. $data = [
  1304. 'name' => \Setting::get('love.name') ?: '爱心值',
  1305. 'deduction' => 0, //是否开启爱心值抵扣 0否,1是
  1306. 'deduction_proportion' => 0, //爱心值最高抵扣
  1307. 'award' => 0, //是否开启爱心值奖励 0否,1是
  1308. 'award_proportion' => 0, //奖励爱心值
  1309. ];
  1310. $love_set = \Setting::get('love');
  1311. $res = app('plugins')->isEnabled('store-cashier');
  1312. if ($res) {//门店抵扣设置
  1313. $store_goods = StoreGoods::where('goods_id', $goods_id)->first();
  1314. $love = StoreSetting::getStoreSettingByStoreId($store_goods->store_id)->where('key', 'love')->first();
  1315. $set = \Setting::get('plugin.store_widgets', 'deduction_proportion');
  1316. // dd($set['love']['deduction_proportion'],$love->value['deduction_proportion']);
  1317. }
  1318. $item = GoodsLove::ofGoodsId($goods->id)->first();
  1319. // dd($item->deduction);
  1320. $deduction = 0;
  1321. // $deduction_proportion = (bccomp($item->deduction_proportion, 0.00, 2) == 1) ? $item->deduction_proportion : \Setting::get('love.deduction_proportion');
  1322. $deduction_proportion = \Setting::get('love.deduction_proportion');
  1323. if ($item->deduction) {//商品独立设置
  1324. if ($love_set['deduction']) {
  1325. $deduction_proportion = $love_set['deduction_proportion'];
  1326. $deduction = $love_set['deduction'];
  1327. }
  1328. // if (!empty($set['love']['deduction'])){//平台设置
  1329. // $deduction_proportion = $set['love']['deduction_proportion'];
  1330. // $deduction = $set['love']['deduction'];
  1331. // }
  1332. // $price = $goods->price * ($deduction_proportion / 100);love[deduction_proportion_low]
  1333. if (!empty($love) && $love->value['deduction_proportion'] && $love->value['deduction_proportion'] != 0) {//门店设置
  1334. $deduction_proportion = $love->value['deduction_proportion'];
  1335. $deduction = $love->value['deduction'];
  1336. }
  1337. if ($item->deduction_proportion && $item->deduction_proportion != 0) {
  1338. $deduction_proportion = $item->deduction_proportion;
  1339. $deduction = $item->deduction;
  1340. }
  1341. $data['deduction'] = $deduction;//$item->deduction;
  1342. $data['deduction_proportion'] = $deduction_proportion . '%';
  1343. }
  1344. // $award_proportion = (bccomp($item->award_proportion, 0.00, 2) == 1) ? $item->award_proportion : \Setting::get('love.award_proportion');
  1345. if ($item->award) {
  1346. $award = $item->award;
  1347. //爱心值插件设置
  1348. $award_proportion = \Setting::get('love.award_proportion');
  1349. //平台设置
  1350. // if (!empty($set)){
  1351. // $award_proportion = $set['love']['award_proportion'];
  1352. // $award = $set['love']['award'];
  1353. // }
  1354. // $award_price = $goods->price * ($award_proportion / 100);
  1355. //门店设置
  1356. if (!empty($love) && $love->value['award_proportion'] && $love->value['award_proportion'] != 0) {
  1357. $award_proportion = $love->value['award_proportion'];
  1358. $award = $love->value['award'];
  1359. }
  1360. //商品独立设置
  1361. if ($item->award_proportion && $item->award_proportion != 0) {
  1362. $award_proportion = $item->award_proportion;//bccomp($item->award_proportion, 0.00, 2);
  1363. $award = $item->award;
  1364. }
  1365. $data['award'] = $love_set['award'] ? $award : 0;//$item->award;
  1366. $data['award_proportion'] = $award_proportion . '%';
  1367. }
  1368. // dd(\Setting::get('love.award_proportion'),$set['love']['award_proportion'],$love->value['award_proportion'],$item->award_proportion,bccomp(66, 0.00, 2));
  1369. return $data;
  1370. }
  1371. /**
  1372. * 是否开启领优惠卷
  1373. * @param $member
  1374. * @return \Illuminate\Http\JsonResponse|int
  1375. */
  1376. public function couponsMemberLj($member)
  1377. {
  1378. if (empty($member)) {
  1379. throw new AppException('没有找到该用户');
  1380. }
  1381. $memberLevel = $member->level_id;
  1382. $now = strtotime('now');
  1383. $coupons = Coupon::getCouponsForMember($member->member_id, $memberLevel, null, $now)
  1384. ->orderBy('display_order', 'desc')
  1385. ->orderBy('updated_at', 'desc')
  1386. ->get();
  1387. if ($coupons->isEmpty()) {
  1388. return 0;
  1389. }
  1390. foreach ($coupons as $v) {
  1391. if (($v->total == MemberCouponController::NO_LIMIT) || ($v->has_many_member_coupon_count < $v->total)) {
  1392. return 1;
  1393. }
  1394. }
  1395. return 0;
  1396. }
  1397. private function goods_lease_set(&$goodsModel, $lease_switch)
  1398. {
  1399. if ($lease_switch) {
  1400. //TODO 商品租赁设置 $id
  1401. if (is_array($goodsModel)) {
  1402. $goodsModel['lease_toy'] = LeaseToyGoods::getDate($goodsModel['id']);
  1403. } else {
  1404. $goodsModel->lease_toy = LeaseToyGoods::getDate($goodsModel->id);
  1405. }
  1406. } else {
  1407. if (is_array($goodsModel)) {
  1408. $goodsModel['lease_toy'] = [
  1409. 'is_lease' => $lease_switch,
  1410. 'is_rights' => 0,
  1411. 'immed_goods_id' => 0,
  1412. ];
  1413. } else {
  1414. $goodsModel->lease_toy = [
  1415. 'is_lease' => $lease_switch,
  1416. 'is_rights' => 0,
  1417. 'immed_goods_id' => 0,
  1418. ];
  1419. }
  1420. }
  1421. }
  1422. public function loveShoppingGift($goodsModel)
  1423. {
  1424. //爱心值
  1425. $exist_love = app('plugins')->isEnabled('love');
  1426. if ($exist_love) {
  1427. $love_goods = $this->getLoveSet($goodsModel, $goodsModel->id);
  1428. if ($love_goods['award'] && \Setting::get('love.goods_detail_show_love') == 2) {
  1429. return '购买赠送' . $love_goods['award_proportion'] . $love_goods['name'];
  1430. }
  1431. }
  1432. return '';
  1433. }
  1434. private function goodsServiceFree(&$goodsModel)
  1435. {
  1436. if (app('plugins')->isEnabled('service-fee')) {
  1437. $serviceFee = Setting::get('plugins.service-fee');
  1438. if ($serviceFee['service']['open'] == 1) {
  1439. $serviceFees = ServiceFeeModel::where('goods_id', $goodsModel->id)->first();
  1440. if ($serviceFees->is_open) {
  1441. $fee = ['name' => $serviceFee['service']['name'], 'money' => $serviceFees->fee];
  1442. $goodsModel->fee = $fee;
  1443. }
  1444. }
  1445. }
  1446. return;
  1447. }
  1448. private function goodsProductMarket(&$goodsModel)
  1449. {
  1450. if (app('plugins')->isEnabled('product-market')) {
  1451. $productMarket = ProductMarketGoodsModel::where('goods_id', $goodsModel->id)->first();
  1452. if ($productMarket['product']) {
  1453. $goodsModel->prdocut_market = $productMarket['product'];
  1454. }
  1455. }
  1456. if (app('plugins')->isEnabled('market-sub')) {
  1457. $productMarket = MarketSubGoods::where('goods_id', $goodsModel->id)->first();
  1458. if ($productMarket['product']) {
  1459. $goodsModel->prdocut_market = $productMarket['product'];
  1460. }
  1461. }
  1462. return;
  1463. }
  1464. public function showPush()
  1465. {
  1466. $id = intval(\YunShop::request()->id);
  1467. $goods = Goods::with('hasOneSale')->find($id);
  1468. $show_push = SaleGoods::getPushGoods($goods->hasOneSale);//SaleGoods::getPushGoods($goodsModel->hasOneSale)
  1469. $data['show_push'] = $show_push ?: [];
  1470. $data['content'] = html_entity_decode($goods->content) ?: '';
  1471. return $this->successJson('返回成功', $data);
  1472. }
  1473. public function getComment($goodsId)
  1474. {
  1475. app('db')->cacheSelect = true;
  1476. // $goodsId = \YunShop::request()->goods_id;
  1477. $pageSize = 5;
  1478. $list = Comment::getCommentsByGoods($goodsId)->paginate($pageSize);//
  1479. if ($list) {
  1480. foreach ($list as &$item) {
  1481. $item->nick_name = self::substrCut($item->nick_name);
  1482. $item->reply_count = $item->hasManyReply->count('id');
  1483. $item->head_img_url = $item->head_img_url ? replace_yunshop(yz_tomedia($item->head_img_url)) : yz_tomedia(\Setting::get('shop.shop.logo'));
  1484. }
  1485. //对评论图片进行处理,反序列化并组装完整图片url
  1486. $list = $list->toArray();
  1487. foreach ($list['data'] as &$item) {
  1488. self::unSerializeImage($item);
  1489. }
  1490. return $list;
  1491. }
  1492. return $list;
  1493. }
  1494. /*
  1495. * 获取商品好评率
  1496. */
  1497. public function favorableRate($id)
  1498. {
  1499. //不跟订单关联的新好评率计算公式
  1500. $total = \app\common\models\Comment::where(['goods_id' => $id, 'type' => 1])->count('id');//总评论数
  1501. if ($total <= 0) return '100%';
  1502. $level_comment = \app\common\models\Comment::where(['goods_id' => $id, 'type' => 1])->sum('level');//已评论的分数
  1503. $mark = bcmul($total, 5, 2);//最高总评分 = 总条数 * 5
  1504. //最终好评率 = (已评论分数/最高总评分)/100
  1505. $have_comment = bcmul(bcdiv($level_comment, $mark, 2), 100, 2);
  1506. return $have_comment . '%';
  1507. // $total = OrderGoods::with(['hasOneOrder',function($q){
  1508. // $q->where('status',3);
  1509. // }])->where('goods_id',$id)->count('id');//总条数
  1510. //
  1511. // if ($total <= 0){
  1512. // return '100%';
  1513. // }
  1514. // $level_comment = \app\common\models\Comment::where(['goods_id' => $id,'type'=> 1])->sum('level');//已评论的分数
  1515. // $comment = \app\common\models\Comment::where(['goods_id' => $id,'type'=>1])->count('id');//总评论数
  1516. // $mark = bcmul($total,5,2);//总评分 = 总条数 * 5
  1517. // $no_comment = bcmul(bcsub($total,$comment,2) ,5,2);//未评分 = 总条数 - 已评论条数
  1518. // $have_comment = bcmul(bcdiv(bcadd($level_comment,$no_comment,2),$mark,2),100,2);//最终好评率
  1519. // //最终好评率 = ((已评论分数 + 未评分) / 总评分)/100
  1520. // return $have_comment.'%';
  1521. }
  1522. // 反序列化图片
  1523. public static function unSerializeImage(&$arrComment)
  1524. {
  1525. $arrComment['images'] = unserialize($arrComment['images']);
  1526. foreach ($arrComment['images'] as &$image) {
  1527. $image = yz_tomedia($image);
  1528. }
  1529. // if ($arrComment['append']) {
  1530. // foreach ($arrComment['append'] as &$comment) {
  1531. // $comment['images'] = unserialize($comment['images']);
  1532. // foreach ($comment['images'] as &$image) {
  1533. // $image = yz_tomedia($image);
  1534. // }
  1535. // }
  1536. // }
  1537. if ($arrComment['append']) {
  1538. $arrComment['append']['images'] = unserialize($arrComment['append']['images']);
  1539. foreach ($arrComment['append']['images'] as &$image) {
  1540. $image = yz_tomedia($image);
  1541. }
  1542. }
  1543. if ($arrComment['has_many_reply']) {
  1544. foreach ($arrComment['has_many_reply'] as &$comment) {
  1545. $comment['images'] = unserialize($comment['images']);
  1546. foreach ($comment['images'] as &$image) {
  1547. $image = yz_tomedia($image);
  1548. }
  1549. }
  1550. }
  1551. }
  1552. //直播间
  1553. public function getRoom()
  1554. {
  1555. app('db')->cacheSelect = true;
  1556. $goods_id = intval(request()->goods_id);
  1557. $rooms = Room::select('yz_room.*', 'yz_room_record_file.id as back_id')
  1558. ->where(function ($querys) {
  1559. $querys->whereIn('status', [2, 3])
  1560. ->orwhere(function ($query) {
  1561. $query->where('status', 4)
  1562. ->where('yz_room_record_file.id', '>', 0)
  1563. ->where('yz_room_record_file.is_show', 1);
  1564. });
  1565. })
  1566. ->leftJoin('yz_room_record_file', function ($join) {
  1567. $join->on('yz_room_record_file.room_id', '=', 'yz_room.id');
  1568. })
  1569. ->with('hasOneMember')
  1570. ->wherehas('hasManyGoods', function ($query) use ($goods_id) {
  1571. $query->where('goods_id', $goods_id);
  1572. })
  1573. ->whereNull('yz_room_record_file.deleted_at')
  1574. ->orderByRaw("FIELD(status, " . implode(", ", [3, 2, 4]) . ")")
  1575. ->orderBy('yz_room.recommend', 'asc')
  1576. ->orderBy('yz_room_record_file.recommend', 'asc')
  1577. ->orderBy('yz_room.id', 'desc')
  1578. ->paginate(10);
  1579. $room = [];
  1580. foreach ($rooms as $key => $val) {
  1581. $room[$key]['avatar'] = $val->hasOneMember['avatar_image'];
  1582. $room[$key]['nickname'] = $val->hasOneMember['nickname'];
  1583. $room[$key]['id'] = $val->id;
  1584. $room[$key]['status'] = $val->status;
  1585. $room[$key]['title'] = $val->title;
  1586. $room[$key]['cover'] = yz_tomedia($val->cover);
  1587. $room[$key]['banner'] = yz_tomedia($val->banner);
  1588. $room[$key]['live_time'] = $val->live_time;
  1589. $room[$key]['view_num'] = $val->view_count + $val->virtual;
  1590. if (empty($val->goods)) {
  1591. $room[$key]['goods_num'] = 0;
  1592. } else {
  1593. $room[$key]['goods_num'] = count(explode(',', $val->goods));
  1594. }
  1595. if ($val->status == 2) {
  1596. $room[$key]['play_type'] = 3;
  1597. } elseif ($val->status == 3) {
  1598. $room[$key]['play_type'] = 1;
  1599. } else {
  1600. $room[$key]['play_type'] = 2;
  1601. $room[$key]['back_id'] = $val->back_id;
  1602. }
  1603. }
  1604. $json = $rooms->toArray();
  1605. $json['data'] = $room;
  1606. return $this->successJson('成功', $json);
  1607. }
  1608. /**
  1609. * 只保留字符串首尾字符,隐藏中间用*代替(两个字符时只显示第一个)
  1610. * @param string $user_name 姓名
  1611. * @return string 格式化后的姓名
  1612. */
  1613. function substrCut($user_name)
  1614. {
  1615. $strlen = mb_strlen($user_name, 'utf-8');
  1616. $firstStr = mb_substr($user_name, 0, 1, 'utf-8');
  1617. $lastStr = mb_substr($user_name, -1, 1, 'utf-8');
  1618. if ($strlen < 2) {
  1619. return $user_name;
  1620. } else {
  1621. return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
  1622. }
  1623. }
  1624. }