save($params); $productIds = StoreProduct::where('two_cate_id', 'in', $secondCateIds)->whereOr('cate_id', 'in', $thirdCateIds)->column('id'); $productInfo = []; $time = time(); foreach ($productIds as $productId) { $productInfo[] = [ 'product_id' => $productId, 'form_id' => $activityZoneForm->id, 'create_time' => $time, 'update_time' => $time, ]; } if (!empty($productInfo)) { ActivityZone::insertAll($productInfo); } Db::commit(); return true; } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } } /** * @notes 编辑 * @param array $params * @return bool * @author admin * @date 2024/12/20 10:52 */ public static function edit(array $params): bool { Db::startTrans(); try { ActivityZoneForm::where('id', $params['id'])->update([ 'type' => $params['type'], 'product_id' => $params['product_id'], ]); Db::commit(); return true; } catch (\Throwable $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } } /** * @notes 删除 * @param array $params * @return bool * @author admin * @date 2024/12/20 10:52 */ public static function delete(array $params): bool { return ActivityZoneForm::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author admin * @date 2024/12/20 10:52 */ public static function detail($params): array { return ActivityZoneForm::findOrEmpty($params['id'])->toArray(); } public static function export($params) { $service = new ActivityZoneService(); $activityZoneForm = ActivityZoneForm::findOrEmpty($params['id'])->toArray(); $products = ActivityZone::with('product')->field('id,product_id')->where('form_id', $params['id'])->select()->toArray(); $unitIds = array_unique(array_column($products, 'unit')); $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); $unit = reset_index($unit, 'id'); foreach ($products as &$item) { $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; unset($item['unit'], $item['product_id']); } $data = ConfigLogic::getDictByType('activity_zone'); foreach ($data['activity_zone'] as $value) { if ($value['value'] == $activityZoneForm['type']) { $typeName = $value['remark']; break; } } return $service->export($products, $activityZoneForm['title'], $typeName ?? '', $activityZoneForm['remark']); } }